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-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!

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.

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