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
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
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
;
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;
Here is a tool I wrote recently to accomplish your task
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.