BookmarkSubscribeRSS Feed
Apprentice
Calcite | Level 5

How can I pass a table column as a parameter in a macro?

Example of what I intend to do:

data xyz;

   input userid;

   datalines;

1

2

;

run;

%macro looper (userid);

...

...

%mend looper;

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thats exactly the way.  Describe further what you problems are, test data/required output is also good.

Astounding
PROC Star

Do you want to call %LOOPER just once, or do you want to call it for each observation in XYZ?

Apprentice
Calcite | Level 5

I want to call % LOOPER for each observation in table XYZ

RW9
Diamond | Level 26 RW9
Diamond | Level 26

data _null_;

     set XYZ;

     call execute('%looper ('||strip(user)||');');

run;

However there are probably better ways of doing it, but without the rest of the information its hard to say.

data_null__
Jade | Level 19

One again I will remind you of the importance of timing with the macro language and the fact that CALL EXECUTE has subtleties that most do NOT understand.

T

The following example uses the %NRSTR macro quoting function to mask the macro statement. This function will delay the execution of macro statements until after a step boundary.

call execute('%nrstr(%sales('||month||'))');

While it may not matter for the programs that you write we have not seen the OP's program and have no idea what the OP will come up with. 

SAS(R) 9.4 Macro Language: Reference, Third Edition

Apprentice
Calcite | Level 5

Thanks; this will do it.

sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10

It would be considerate as well to explain why you want to perform such processing, as much as there may be a more effective / efficient technical approach - specifically what is your objective and how might you intend to use the SAS observation content with each macro invocation?  It appears that LOOPER is intended to be a code-piece executed within the SAS DATA step you have illustrated, although you have the %MACRO %MEND definition coded after the RUN;  statement which will most definitely short-circuit the processing you desire to achieve.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1815 views
  • 3 likes
  • 5 in conversation