data test;
length varlist $1000;
varlist= " data x;length name $25; name='abc'; output; name='edfs'; output; run;";
run;
data _null_;
set test end=eof;
if eof then call symputx('step',varlist);
run;
%put %superq(&step);
I got it to work with Call execute as below, is there any other suggestions? Thank you.
data test;
length varlist $1000;
varlist= " data x;length name $25; name='abc'; output; name='edfs'; output; run;";
run;
data _null_;
set test end=eof;
if eof then call symputx('step',varlist);
call execute('%NRSTR(' || "&step" || ')');
run;
%put %superq(step);
Remove the & from your code. The %SUPERQ() function wants the NAME of a macro variable, not its value.
%put %superq(step);
Thanks looks like I had &step, when I was calling superq. How can I execute those?
I got it to work with Call execute as below, is there any other suggestions? Thank you.
data test;
length varlist $1000;
varlist= " data x;length name $25; name='abc'; output; name='edfs'; output; run;";
run;
data _null_;
set test end=eof;
if eof then call symputx('step',varlist);
call execute('%NRSTR(' || "&step" || ')');
run;
%put %superq(step);
If the goal is just to run it immediately then there is no need to put it into a macro variable.
call execute(trim(varlist));
Or instead of macro variables you can put it into an actual FILE.
filename code temp;
data _null_;
set test;
file code;
put varlist;
run;
And then use %INCLUDE to run it.
%include code / source2;
What do you want to do when you have more than one block of code to store?
For example perhaps you have a dataset that is something like this:
data test;
step+1;
length varlist $1000;
varlist= " data x;length name $25; name='abc'; output; name='edfs'; output; run;";
output;
step+1;
varlist='proc print data=x; run;';
output;
run;
Now you can put it into multiple macro variables.
data _null_;
set test;
call symputx(cats('step',step),varlist);
run;
Which you can then run independently.
&step1
proc sort data=x;
by name;
run;
&step2
Or perhaps just run them using call execute;
data _null_;
set test;
call execute(catx(' ','* STEP',step,';'));
call execute(trim(varlist));
run;
Just expand the macro variable between other steps in your program.
proc print data=sashelp.class;
run;
&step
proc print data=x;
run;
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.
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.
Ready to level-up your skills? Choose your own adventure.