Help using Base SAS procedures

data step

Reply
Super Contributor
Posts: 272

data step

I am creating multiple datasets from one dataset using the following code. Do I have list all the 23 dataset names. Is ther way like a1-a23 (this didnot work) i can use to simplify. Thanks.

 

data a1 a2 a3 a4 a5 a6 a7 to a23;

set b;

if then do;

end;

output a1;

end;

run;

 

Super User
Posts: 17,963

Re: data step

If you want to do it that way, then yes you do have to list it out. There are other ways, but the general advice is don't do this.

Your posted code isn't correct, but I'm assuming you have more data somewhere.

 

http://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/

 

And here:

 

http://www.sascommunity.org/wiki/Split_Data_into_Subsets

Super User
Posts: 10,550

Re: data step

Unfortunately what you are doing pretty much requires an exact list.

There are some methods to generate lists. One might ask the need for splitting one data set that many ways. Since you are going to have 23 conditions to output the data I wouldn't worry so much about this list of sets.

It may be that your later data processing could use the concept of BY where it will do the same thing for each value of a variable in your data.

 

Valued Guide
Posts: 858

Re: data step

This example may help:

 

data teams;
input team$;
cards;
TeamA
TeamA
TeamA
TeamB
TeamB
TeamB
;

data _null_;
   set teams;
   by team;
   if first.team then do;
      call execute("data "||team||";");
      call execute ("set teams (where=(team ='"||strip(team)||"')); run;");
   end;
run;

Super User
Posts: 5,260

Re: data step

You could use a macro approach with %do loops to generate data set nsmed and logic dynamic.
But I agree with @Reeza that splitting data usually is not benificial. Reporting and statistical analysis is supported best by bringing data together, not splitting them apart.
Data never sleeps
Ask a Question
Discussion stats
  • 4 replies
  • 341 views
  • 1 like
  • 5 in conversation