Hi folks,
I store several lists in a series of macros. However, the macros are not resolved. Anything wrong here? Thanks
data ParamData;
input x @@;
datalines;
1 2 3 4 5
;
%macro whatever;
%do i=1 %to 5;
proc sql ;
select x into :ParamList&i separated by ' '
from ParamData where x<&i+1;
quit;
%end;
%mend;
%whatever;
%put ParamList = &ParamList1;
%macro whatever;
%do i=1 %to 5;
%global paramlist&i;
proc sql ;
select x into :paramList&i separated by ' '
from ParamData where x<&i+1;
quit;
%end;
%mend;
%whatever
You need the %global command. Otherwise, macro variables defined inside a macro cannot be used outside the macro.
Furthermore, in the future, please paste your SAS code into the window that appears when you click on the "running man" icon, and then you won't have smiley faces in your SAS code.
The macro variables are local to the macro. Use %global.
And use the proper methods for posting code and logs. "Little running man" for code, {i} for logs. The main posting window scrambles the text.
%macro whatever;
%do i=1 %to 5;
%global paramlist&i;
proc sql ;
select x into :paramList&i separated by ' '
from ParamData where x<&i+1;
quit;
%end;
%mend;
%whatever
You need the %global command. Otherwise, macro variables defined inside a macro cannot be used outside the macro.
Furthermore, in the future, please paste your SAS code into the window that appears when you click on the "running man" icon, and then you won't have smiley faces in your SAS code.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.