SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
jjb123
Obsidian | Level 7

This is probably a question that has been asked many times and answered, but I'm not finding the info I want.  I want to do something like the following and would love some advice (or even links to the question being answered).  I basically want to be able to do something like this while being able to just list multiple variables at the top (like %let variable = x, y, z, etc.).  So I want it to be able to loop through multiple variables and perform the same procedures and give the different outputs.  

%let variable = x;

/*then do data manipulations, etc*/

proc export data = xyz outfile = "C:\Users\person\Desktop\'&variable'.dta" replace;
run;

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

You can do something along these lines

 

data callstack;
   length string $500;
   do var='x', 'y', 'z';
   string=compbl(cats(
      "
      proc export data = xyz outfile = 'C:\Users\person\Desktop\", var, ".dta' replace;
      run;
      "
      ));
   output;
   call execute(string);
   end;
run;
jjb123
Obsidian | Level 7

Thanks for the response.  However, there are hundreds of lines of data manipulations that I perform on each variable, so using call execute gets very messy very quickly. Do you have any other suggestions?

PaigeMiller
Diamond | Level 26

Then you need a macro with nested %DO loops for the multiple variables. Since you have not provided any more details, there's really not much detail I can provide back to you.

--
Paige Miller

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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