Hi:
Generally speaking, it is a good idea to start with a working SAS program -before- you "macro-ize" the program. In the regular SAS world, without any macro code involved, this would be problematic SAS code:
[pre]
data temp3;
set temp2;
low=0;
high=10;
increment=1;
*** --- *** PROC Step is step boundary to data step program;
PROC corr alpha noprob nomiss nocorr;
VAR DEPRESS_mood IRRITBLT ANHEDONIA WEIGHT SLEEP PMOTOR FATIGUE ESTEEM THOUGHT SUICIDE;
run; <--This is step boundary for PROC CORR step;
*** --- *** Next two statements would be in "open code;
low = low + increment;
high = high + increment;
if high le 30 then continue;
*** --- *** end of steps in open code;
[/pre]
The reason I say that the "non-macro" code is problematic is that the PROC CORR statement will act as the step boundary to the DATA step program. Defining a SAS macro program (what's inside %MACRO/%MEND) is not the same as -RUNNING- or invoking a SAS Macro program.
Consider this -working- SAS program (which uses SASHELP.CLASS):
[pre]
ods listing;
PROC corr data=sashelp.class alpha noprob nomiss nocorr;
where age = 12;
VAR age height weight;
run;
PROC corr data=sashelp.class alpha noprob nomiss nocorr;
where age = 13;
VAR age height weight;
run;
PROC corr data=sashelp.class alpha noprob nomiss nocorr;
where age = 14;
VAR age height weight;
run;
PROC corr data=sashelp.class alpha noprob nomiss nocorr;
where age = 15;
VAR age height weight;
run;
[/pre]
The program consists of 4 PROC CORR steps...each with a different WHERE statement. Each PROC CORR step is essentially the same except for the WHERE statement. A valid SAS macro program DEFINITION would then be:
[pre]
%macro docorr(age=);
ods listing;
PROC corr data=sashelp.class alpha noprob nomiss nocorr;
title "PROC CORR for Age = &age";
where age = &age;
VAR age height weight;
run;
%mend docorr;
[/pre]
But, that is just the DEFINITION. Now I have to INVOKE the macro program. To invoke the %DOCORR macro program, which causes the PROC CORR step to be actually sent to the SAS compiler, I need to do this:
[pre]
options mprint symbolgen mlogic;
%docorr(age=12)
%docorr(age=13)
%docorr(age=14)
%docorr(age=15)
[/pre]
The %DOCORR macro statement is actually where the macro program is INVOKED and the (age=12) or (age=13) is a keyword parameter that provides necessary information for the WHERE statement and the TITLE statement in the macro program.
Note how the %MACRO and %MEND do not actually cause any statements to be executed. All that happens when the macro compiles successfully is that the macro program is stored in the WORK.SASMACR catalog -- where the macro program sits and waits to be invoked.
I could have written the macro program differently -- to contain a %DO loop, like this:
[pre]
%macro altcorr;
ods listing;
%do age = 12 %to 15;
PROC corr data=sashelp.class alpha noprob nomiss nocorr;
title "Alternate PROC CORR for Age = &age";
where age = &age;
VAR age height weight;
run;
%end;
%mend altcorr;
[/pre]
And, then the above macro program would be invoked just 1 time
[pre]%altcorr;[/pre]
and the %DO loop would cause 4 PROC CORR steps to be written to the compiler. Each time a PROC CORR step was generated, the %DO loop would automatically increment the AGE macro variable. I used a simple %DO loop instead of a more complex loop because it is easier to explain.
There are ways to use a DATA step program to write code for you and use a CALL EXECUTE inside a DATA step program to place code into the queue for the compiler. You, cannot, however, create macro variables in a DATA step program and then use those macro variables in the same program. SAS must encounter a step boundary before those macro variables are available to you.
In a similar vein, you cannot use DATA step variables in your macro %DO loop, as you attempt in your %DO %WHILE loop. Your DATA step variables are not available to the macro processor. There are ways to make your macro program create and use DATA step variables out of the Program Data Vector, but the method you are trying won't work.
I recommend that you read the documentation on how the macro facility operates with a data step program before you go much further with this attempt.
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/getstart.htm
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/tw3514-definemacro.htm
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001302436.htm
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/tw3514-symput.htm
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001072359.htm
The documentation on the macro facility is very good. In addition, there are lots of previous forum postings on some of the macro facility basics and I find this user group paper is an excellent introduction to the topic.
http://www2.sas.com/proceedings/sugi28/056-28.pdf
A Google search would reveal other papers on the Macro facility -- from the beginner level to the advanced level. Here are some Google search strings to try:
SAS macro beginner
SAS macro tutorial
SAS macro %DO
cynthia