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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: