Hi:
Just a finicky teacher here....in order to keep things straight, where macro definition happens, where macro compilation happens, when data step compilations happens, when data step execution happens, my recommendation would be to NOT write your program like this:
[pre]
DATA TEMP (KEEP=NAME DAYS_AWAY_SUM DAYS_AWAY1-DAYS_AWAY377);
SET SIX;
DAYS_AWAY_SUM = 0;
%MACRO SUMDAYS;
%DO I = 1 %TO 377;
IF DAYS_AWAY&I NE . THEN DAYS_AWAY_SUM = DAYS_AWAY_SUM + DAYS_AWAY&I;
%END;
%MEND SUMDAYS;
%SUMDAYS;
RUN;
[/pre]
A more accurate way to create and then invoke the macro program is like this:
[pre]
** macro program is compiled and stored in WORK.SASMACR catalog;
%MACRO SUMDAYS;
%DO I = 1 %TO 377;
IF DAYS_AWAY&I NE . THEN DAYS_AWAY_SUM = DAYS_AWAY_SUM + DAYS_AWAY&I;
%END;
%MEND SUMDAYS;
** now use the compiled macro program to generate 377 IF statements;
DATA TEMP (KEEP=NAME DAYS_AWAY_SUM DAYS_AWAY1-DAYS_AWAY377);
SET SIX;
DAYS_AWAY_SUM = 0;
%SUMDAYS;
RUN;
[/pre]
But, apart from that, if you used a SAS ARRAY, you would not need to generate 377 IF statements using a MACRO %DO loop. Instead, your DATA step DO loop would be:
[pre]
array da days_away:;
...
do i = 1 to dim(da);
if da(i) ne . then d_a_sum = d_a_sum + da(i);
end;
[/pre]
The colon modifier in the variable list makes ALL variables that start "days_away" as array members. This means that you can now have a regular data step DO loop that goes from 1 to the DIM(array-name) -- for my second DATA step program, I did -NOT- have to know that the first program created 19 numbered variables.
Is there a reason you were using a MACRO loop instead of an ARRAY and a DATA step loop????
cynthia
** Here is a program that illustrates the use of ARRAYs;
[pre]
** make data with an array;
** this would be your proc transpose step;
data classarr;
set sashelp.class;
array da days_away1-days_away19;
do i = 1 to 19;
da(i) = age * i + height;
end;
output;
run;
** note that I do not need to know size of array for this step to work;
** but ALL the variables that start with "days_away" will be array members;
** so I named the SUM variable something different.;
data testarr;
set classarr;
array da days_away:;
d_a_sum = 0;
do i = 1 to dim(da);
if da(i) ne . then d_a_sum = d_a_sum + da(i);
end;
run;
ods listing;
proc print data=testarr;
run;
[/pre]