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
Works for me without errors. Post your log please?
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.
You might be looking in the wrong place. The data set TestDt1 never changes. The second run creates TestDt2, it doesn't replace TestDt1.
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?
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.