Splitting a SAS dataset into multiple datasets, ac

2019-08-21 14:37发布

Is there a more streamlined way of accomplishing this? This is a simplified example. In the real case there are > 10 values of var, each of which need their own dataset.

data 
  new1
  new2
  new3;
set old;

if var = 'new1' then output new1;
else if var = 'new2' then output new2;
else if var = 'new3' then output new3;
run;

标签: sas
1条回答
别忘想泡老子
2楼-- · 2019-08-21 15:33

This should work out. You just need to change the %to 5 to 10 (the max new number). The point made by @Reeza is great. I would also take a look at that post since it's an important suggestion. Usually this is not a good way to handle data, but this should get you around.

data have;
input      var $;
datalines;
            new1
            new2 
            new3 
            new4 
            new5 
;
run;

*Actual code starts here;

%macro splitting;
%do i=1 %to 5;

%put "new&i";

proc sql;
    create table table&i as 
    select *
    from have
    where var contains "new&i";
quit;

%end;
%mend splitting; 

%splitting;
查看更多
登录 后发表回答