BookmarkSubscribeRSS Feed
GallagherML
Calcite | Level 5

Hi everyone,

 

I am trying to run a macro with two variables Test1 and Test2. 

 

%macro TestMacro (Test1=,Test2=,Num=);

DATA WORK.TestDt&Num;
Mean=MEAN(&Test1,&Test2);
RUN;

%mend TestMacro;

%TestMacro (Test1=19,Test2=20,Num=1);
%TestMacro (Test1=16,Test2=19.8,Num=2);
%TestMacro (Test1=18.9,Test2=17.6,Num=3);

It works fine when I only run it once. However, the macro stops after the first run, even though there are two left that I included at the same time. I don't know if that is what is supposed to happen, or if I haven't figured out how to run multiple macros at the same time yet. Clarification would be great!

Thanks y'all

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Works for me without errors. Post your log please?

Kurt_Bremser
Super User

Works:

 73         %macro TestMacro (Test1=,Test2=,Num=);
 74         
 75         DATA WORK.TestDt&Num;
 76         Mean=MEAN(&Test1,&Test2);
 77         RUN;
 78         
 79         %mend TestMacro;
 80         
 81         %TestMacro (Test1=19,Test2=20,Num=1);
 
 NOTE: The data set WORK.TESTDT1 has 1 observations and 1 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 82         %TestMacro (Test1=16,Test2=19.8,Num=2);
 
 NOTE: The data set WORK.TESTDT2 has 1 observations and 1 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 83         %TestMacro (Test1=18.9,Test2=17.6,Num=3);
 
 NOTE: The data set WORK.TESTDT3 has 1 observations and 1 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds

Please post your log, using the </> button as I did.

Astounding
PROC Star

You might be looking in the wrong place.  The data set TestDt1 never changes.  The second run creates TestDt2, it doesn't replace TestDt1.

hswdl01
Fluorite | Level 6

The code you posted seems to be working fine for me and I don't see anything in the code to suggest it wouldn't work. Did you get any warnings or errors in your log?

sdevenny
Calcite | Level 5

The code worked for me, just make sure that you're checking the dropdown menu under output (if you are on Studio, not sure how this works for other versions). Or, you could include a PROC PRINT in the macro, and then it should print all 3 means as different tables. 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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