BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
themanoj20080
Fluorite | Level 6

Hello Everyone,

 

I am trying to use a macro inside PROC IML and it is giving me an error. Suppose I created a macro named mymacro and I call this macro inside proc iml. I would think 4 will be returned 5 times but it is not. Can anyone explain why this is not working? 


%macro mymacro(A,Y=2); proc iml; Z=&A+&Y; print Z; quit; %mend mymacro; proc iml; do i = 1 to 5; %mymacro(2); end; quit;
1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Try this change to your MYMACRO macro. You only need to call PROC IML once:

 

%macro mymacro(A,Y=2);
Z=&A+&Y;
print Z;
%mend mymacro;

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

Try this change to your MYMACRO macro. You only need to call PROC IML once:

 

%macro mymacro(A,Y=2);
Z=&A+&Y;
print Z;
%mend mymacro;
themanoj20080
Fluorite | Level 6

Got it. Thank you so much. Is this always the case that I don't have to use PROC IML inside a macro?

SASKiwi
PROC Star

@themanoj20080 - Yes, it depends what you want your macro to do. In your case the macro generates statements inside a single PROC IML step so you leave out PROC IML and QUIT statements.

 

Another time you might want to run PROC IML multiple times say with slightly different statements - in this case your macro would include PROC IML and QUIT statements.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 949 views
  • 2 likes
  • 2 in conversation