BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ram_SAS
Obsidian | Level 7
Hi,
Wondering if we need to store a complete SAS steps/ procedure as a macro variable, how can we view those without any log issues and how can we execute those?  Example see below, I am capturing a simple data step in VARLIST, eventually want to capture that as a macro variable (&step) and then execute the resolved macro variable?   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);
run;
%put %superq(&step);
 
1 ACCEPTED SOLUTION

Accepted Solutions
Ram_SAS
Obsidian | Level 7

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);

 

 

 

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

Remove the & from your code.  The %SUPERQ() function wants the NAME of a macro variable, not its value.

%put %superq(step);
Ram_SAS
Obsidian | Level 7

Thanks looks like I had  &step, when I was calling superq.  How can I execute those?

 

 

Ram_SAS
Obsidian | Level 7

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);

 

 

 

Tom
Super User Tom
Super User

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;
Tom
Super User Tom
Super User

Just expand the macro variable between other steps in your program.

proc print data=sashelp.class;
run;

&step

proc print data=x;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1015 views
  • 2 likes
  • 2 in conversation