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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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