BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
liyongkai800
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
%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.

--
Paige Miller

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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.

PaigeMiller
Diamond | Level 26
%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.

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2162 views
  • 0 likes
  • 3 in conversation