01-30-2012 12:02 PM
I am a relative novice at SAS coding. I am attempting to write a MACRO that will continue to call another MACRO until all calculations over a certain threshold have been removed. After each record gets removed over the threshold I need to re-calculate. The basic structure looks something similar to this.
%MACRO Loop (var1, var2);
%let stop = 1;
%Do %until (&stop = 0);
%MACRO Calculate (var3, var4, var5, var6, var7, var8);
SELECT cat('%MH_DIF (', var3, ', ', trim(var4), ', ', trim(var5), ', ', var6, ', ',
trim(var7), ', ', trim(var8), ' ', ');') into :List separated by ' '
WHERE X = &var1 and Y = "&var2";
proc sort data = &var1_&var2;
by descending Calculation;
SELECT calculation, item into :maxvalue, :max
FROM &var1_&var2. (OBS=1)
%if &maxvalue > 1.5 %then
where var5 = &max;
Proc append base = rejects new = rejects1 force;
where var5 ne &max;
%else %let stop = 0;
%Loop (var1, var2);
The big problems I am noticing are that when I mend my macros there are no lines underneath the MEND statement. Furthermore, when I look at the code underneath the MEND Calculate statement I am seeing color in the code, which should not be there for a MACRO. Finally, after I run the code, I notice in the code editor: * PROC SQL RUNNING after the name of the program. When I separate the two MACROs and run them independently, they run fine. And help would be greatly appreciated!!! Thanks in advance!
01-30-2012 12:15 PM
Not sure what your actual issue is, but your program structure looks confused. You should move the definition of the macro CALCULATE outside of the definition of the macro LOOP. You should not need to redefine the macro CALCULATE for every iteration inside of LOOP. You just need to call it with different parameter values or input data.
01-30-2012 12:37 PM
The line that looks like it might cause trouble is
You appear to have built the macro variable LIST as one or more calls to the macro MH_DIFF. If that macro expects to generate SAS statements the first one will be "eaten" by the %PUT statement.
If you just want to see the value of the macro variable LIST then use
If you want to actually run the macro calls generated into the macro variable then use