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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 645 views
  • 0 likes
  • 3 in conversation