BookmarkSubscribeRSS Feed
AvocadoRivalry
Calcite | Level 5

Hi all,

I have a field called CLIENT_NAME that has several different entries that can change depending on the dataset I'm feeding in.  Because there is room for variation, using a macro to define the CLIENT_NAME values I want to use won't work each time.  Is there a way to use a DO statement to create a loop that will go through every single unique value for a given variable?  For instance, if I have 26 Client Names in a given dataset, the DO statement would run through the associated block of code 26 times, ultimately producing 26 datasets.

Thanks!

2 REPLIES 2
Tom
Super User Tom
Super User

Normally to generate multiple datasets you will need to use some type of code generation tool.  Either SAS macro code or you can do it yourself with a data step and a %INC.

filename code temp;

data _null_;

  set have ;

  by client_name ;

  if first.client_name;

  file code;

  where = quote(trim(client_name));

  put 'data split_' client_name ';'

     / '  set have;'

     / '  where client_name=' where ';'

    / 'run;'

  ;

run;

%inc code / source2 ;

art297
Opal | Level 21

If the goal is to create separate datasets, and then deal with each separately, why not use a hash? e.g.:

data _null_ ;

  dcl hash hh   (             ) ;

  hh.definekey  ('k'          ) ;

  hh.definedata ('sex', 'name', 'age', 'height', 'weight') ;

  hh.definedone () ;

  do until(mod(k,5)=0 or last);

    k+1;

    set sashelp.class end=last ;

    hh.add();

  end;

  hh.output(dataset: 'a'||strip(k));

run;


SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 802 views
  • 0 likes
  • 3 in conversation