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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.