Output multiple dataset

2019-01-29 11:23发布

问题:

I want output from one dataset to many datasets, so I want to code something like this

data SmallDatasetName_1 - SmallDatasetName_100;
set BigDatasetName;
/*here some code*/
run;

So, if I try this, I get an error. I could solve it (by using select into). But is it exist a "simple" syntax for this, similar to

data BigDatasetName;
set SmallDatasetName_1 - SmallDatasetName_100;
/*here some code*/
run;

?

回答1:

As far as I know, you can't use data set lists in the data statement. You could use a macro to generate your code. First define the macro:

options mprint;
%macro split;
  data 
    %do I = 1 %to 5;
      SmallDatasetName_&I
    %end;;
    set BigDatasetName;
    %do I = 1 %to 5;
      if **your conditions here** then output SmallDatasetName_&I;
    %end;;
  run;
%mend split;

Call the macro using:

%split;

This generates sas code like that looks like this:

data 
  SmallDatasetName_1
  SmallDatasetName_2
  SmallDatasetName_3
  SmallDatasetName_4
  SmallDatasetName_5
  ;
  set BigDatasetName;
  if **your conditions here** then output SmallDatasetName_1;
  if **your conditions here** then output SmallDatasetName_2;
  if **your conditions here** then output SmallDatasetName_3;
  if **your conditions here** then output SmallDatasetName_4;
  if **your conditions here** then output SmallDatasetName_5;
run;


标签: sas