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;


hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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