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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 1721 views
  • 0 likes
  • 3 in conversation