hi i am trying using a macro do loop to populate some variables.
More specifically, when i run the code (see below) for 10 loops the observations are moving down in data (see below this is after 10 times loop) which is not what i need.
I need in every loop to add at the end of each column the additional observations from the calculations inside the macro.
For example, at the beginning of the 2nd loop var17 must have all its observations plus the additional which created from the 1st loop. however, this is not happening. What it happens is var17 moved on step down
Any help it would be appreciated 🙂
| Obs |
date |
var17 |
var18 |
var15 |
| 1 |
31/03/2000 |
. |
. |
. |
| 2 |
30/06/2000 |
. |
. |
. |
| 3 |
30/09/2000 |
. |
. |
. |
| 4 |
31/12/2000 |
. |
. |
. |
| 5 |
31/03/2001 |
. |
. |
. |
| 6 |
30/06/2001 |
. |
. |
. |
| 7 |
30/09/2001 |
. |
. |
. |
| 8 |
31/12/2001 |
. |
. |
. |
| 9 |
31/03/2002 |
. |
. |
. |
| 10 |
30/06/2002 |
. |
. |
. |
| 11 |
30/09/2002 |
. |
. |
. |
| 12 |
31/12/2002 |
. |
. |
. |
| 13 |
31/03/2003 |
. |
. |
. |
| 14 |
30/06/2003 |
. |
. |
. |
| 15 |
30/09/2003 |
. |
. |
. |
| 16 |
31/12/2003 |
. |
. |
. |
| 17 |
31/03/2004 |
. |
. |
. |
| 18 |
30/06/2004 |
. |
. |
. |
| 19 |
30/09/2004 |
. |
. |
. |
| 20 |
31/12/2004 |
. |
. |
. |
| 21 |
31/03/2005 |
. |
. |
. |
| 22 |
30/06/2005 |
. |
. |
. |
| 23 |
30/09/2005 |
-0.7979 |
0.07234 |
-0.41651 |
| 24 |
31/12/2005 |
-0.3274 |
-0.04446 |
0.10851 |
| 25 |
31/03/2006 |
0.0896 |
-0.01812 |
-0.28162 |
| 26 |
30/06/2006 |
-0.3205 |
0.02743 |
0.02995 |
%MACRO example(COUNT);
%DO I = 1 %TO &COUNT;
%DO X = 2 %TO &COUNT;
data data&x;
set data&i;
&var17=lag1(&var15);
run;
PROC SQL;
UPDATE data&x SET &var24=&var17*(-0.1487);
UPDATE data&x SET &var18=&var22 + &var23 + &var24 + d1_co + d2_co + d3_co;
UPDATE data&x SET &var6= &var18;
QUIT;
data data&x;
set data&x;
&var5=lag1(&var5)+ &var6;
&var15= &var5 - &var16;
run;
%end;
%END;
%MEND example;
%example(10);