BookmarkSubscribeRSS Feed
yashpande
Obsidian | Level 7

Hi all,

I have a simple macro

%macro m1(parm1,parm2,parm3);

Process report data = have;

Where id=&parm1 and phone=&parm2 and name="&parm3";

Run;

%mend;

Data have;

Input Id 8. Phone 10. Name $30.;

Cards;

1 1234567890 Rajesh

2 9876543210 Mohan

;

Run;

Now I want to pass values of these observations as parameters to macro.. So my macro calls go like this

%m1(1,1234567890,"Rajesh");

%m1(2,9876543210,"Mohan");

But this is not efficient...Please help

5 REPLIES 5
Reeza
Super User

Use CALL EXECUTE

Example #2 is your situation.

SAS(R) 9.2 Macro Language: Reference

Jagadishkatam
Amethyst | Level 16

I agree with Reeza about using the call execute. Alternatively in similar lines we could use the macro variables.

create macro variables with existing data

proc sql;

select catx(',',id,phone,name) into : par1 - :par&sysmaxlong from have;

quit;

%put &par1 &par2. ;

The &apar1 and &par2 will resolve to the data in respective observation separated by comma.

After this create a new macro test within this macro you could call the previous macro as below.

%macro test;

%do  i = 1 %to 2;

%m1(&&par&i.);

%end;

%mend;

%test;

Please try and let em know if it helps.

Thanks,

Jag

Thanks,
Jag
MadhuKorni
Quartz | Level 8

If you want to generate a report for each and every observation then try this

Data have;

Input Id Phone Name $;

format phone best10.;

call execute("proc report data = have;where id = "||strip(id)||"and phone = "||strip(phone)||"and name = '"||strip(name)||"';run;");

Cards;

1 1234567890 Rajesh

2 9876543210 Mohan

;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As with the above posters, I would also suggest to use call execute.  I would also point out that you can do by group printing as well (and if you want seperate sheets there is an option in excelxp.tagsets):

proc report data=....;

     columns ...;

     by var1 var2;

     title "#byvar1 #byvar2";

     define ...;

run;

Ron_MacroMaven
Lapis Lazuli | Level 10

Here is a tool I wrote recently to accomplish your task

http://www.sascommunity.org/wiki/Macro_CallMacr

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1518 views
  • 0 likes
  • 6 in conversation