Monday, December 20, 2010

SAS ADV 63题之23


First Sort dataset Hihgway and delete duplicated value of Status;

Next value macro variables Status1, Status2... and Count

At last, create two date sets work.NOT and Work.Series;


options nodate nocenter formdlim='*';

data highway;
  input Steering $ Seatbelt $ Speed $ Status $  Count;     
  cards;
  absent    No        0-29   serious     31   
  absent    No        0-29   not       1419   
  absent    No        30-49  serious    191   
  absent    no        30-49  not       2004   
  absent    no        50+    serious    216   
run;

%macro split;
  proc sort data=highway  out=work.uniques(keep=status) nodupkey;
    by status;
  run;

  data _null_;
     set uniques end=lastobs;
       call symputx('status'||left(_n_),status);
       if lastobs then call symputx('count',_n_);
  run;

  %local i;
  data
  %do i=1 %to &count;
    &&status&i
  %end;
  ;
  set highway;
  select(status);
     %do i=1 %to &count;
         when ("&&status&i") output &&status&i;
       %end;
    otherwise;
   end;
   run;

%mend;

%split

No comments:

Post a Comment