Hi:
You still have not simplified your code to the point where
no %DO loops (zip, nada, none, nary a one) are included. If you have to type 6 or 7 assignment statements to understand what your program needs to look like, then type them. You really, really need to understand the code that needs to be generated. I am still not convinced that you need a Macro program. I think you may be confusing iterative ARRAYS and numbered variables with MACRO %DO loops.
Also, do you understand the difference between DATA step compile time and DATA step execution time??? And what happens in each of these phases of a simple program??? Do you understand the difference between an &macvar reference, a call symput as far as the creation of macro variables??? Do you understand what a macro program %macpgm really is and how it ONLY generates code that will get sent forward to the compiler????
OK, then, once you understand that, you have to understand that the SAS Macro facility has a word scanning and macro trigger resolution phase that happens before ANY code is compiled by the "regular" compiler. By the time the word scanning and macro trigger resolution phase is over there are NO &macvar or %macpgm references in your program. So for just one example,...a %LET out in open code will get executed one time, and only one time -- when code is compiled by the "regular" compiler. A %LET statement inside a macro program will work a bit differently, but essentially, a %LET statement does not "communicate" with an executing DATA step program.
Do NOT try to make a shortcut with macros until you understand, really understand, what your working, non-macroized program, looks like. You can also make sure that your program is error free before you go forward with a macro approach. (Because it is very hard to separate out whether your error messages come from your original program or your generated code.) I think that you really need to take a step back and stop thinking about Macro %DO loops and look at ARRAY processing.
For example, the 2 programs below show the difference with a DATA step DO loop WITHOUT an ARRAY and WITH an ARRAY. No macros involved. Which DATA step program -- just for the calculation of "NEWN" variables-- is closer to what you want/need to do?? (LOG output is shown with the result of the PUTLOG statements.)
This is a good introduction to ARRAY processing.
http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf
cynthia
[pre]
NO ARRAYS/NO MACRO
5253 data testit;
5254 ** make the VARN and NEWN variables without any macros;
5255 do i = 0 to 6;
5256 putlog '----- INSIDE TOP of LOOP ' _n_= '|' i= '|' ;
5257 x=uniform(-1);
5258 varn=i + 10;
5259 newn = varn + x;
5260 putlog '----- INSIDE BOTTOM of LOOP ' _n_= '|' i= '|' varn= '|' x= '|' newn= '|';
5261 putlog ' ';
5262 end;
5263
5264 putlog '-----what is in TESTIT -- ONLY 1 OBS';
5265 putlog '-----OUTSIDE of LOOP ';
5266 putlog _all_;
5267 putlog '*************************************************';
5268 run;
----- INSIDE TOP of LOOP _N_=1 |i=0 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=0 |varn=10 |x=0.0328104845 |newn=10.032810485 |
----- INSIDE TOP of LOOP _N_=1 |i=1 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=1 |varn=11 |x=0.7854493804 |newn=11.78544938 |
----- INSIDE TOP of LOOP _N_=1 |i=2 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=2 |varn=12 |x=0.5329144548 |newn=12.532914455 |
----- INSIDE TOP of LOOP _N_=1 |i=3 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=3 |varn=13 |x=0.2107451191 |newn=13.210745119 |
----- INSIDE TOP of LOOP _N_=1 |i=4 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=4 |varn=14 |x=0.1058570995 |newn=14.105857099 |
----- INSIDE TOP of LOOP _N_=1 |i=5 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=5 |varn=15 |x=0.2827750655 |newn=15.282775066 |
----- INSIDE TOP of LOOP _N_=1 |i=6 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=6 |varn=16 |x=0.7087042163 |newn=16.708704216 |
-----what is in TESTIT -- ONLY 1 OBS
-----OUTSIDE of LOOP
i=7 x=0.7087042163 varn=16 newn=16.708704216 _ERROR_=0 _N_=1
*************************************************
NOTE: The data set WORK.TESTIT has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.01 seconds
[/pre]
versus
[pre]
WITH ARRAY/NO MACRO
5270 data testit2;
5271 array new{0:6} newn0-newn6;
5272 ** use an array;
5273 do i = 0 to 6;
5274 putlog '----- INSIDE TOP of LOOP ' _n_= '|' i= '|' ;
5275 x=uniform(-1);
5276 varn=i + 10;
5277 new(i) = varn + x;
5278 putlog '----- INSIDE BOTTOM of LOOP ' _n_= '|' i= '|' varn= '|' x= '|' new(i)= '|';
5279 putlog ' ';
5280 end;
5281
5282 putlog '-----what is in TESTIT2 -- ONLY 1 OBS, but now have variables NEWN0-NEWN6';
5283 putlog '-----OUTSIDE of LOOP ' ;
5284 putlog _all_;
5285 putlog '*************************************************';
5286 run;
----- INSIDE TOP of LOOP _N_=1 |i=0 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=0 |varn=10 |x=0.1132566063 |newn0=10.113256606 |
----- INSIDE TOP of LOOP _N_=1 |i=1 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=1 |varn=11 |x=0.7052701673 |newn1=11.705270167 |
----- INSIDE TOP of LOOP _N_=1 |i=2 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=2 |varn=12 |x=0.8287894241 |newn2=12.828789424 |
----- INSIDE TOP of LOOP _N_=1 |i=3 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=3 |varn=13 |x=0.3050844866 |newn3=13.305084487 |
----- INSIDE TOP of LOOP _N_=1 |i=4 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=4 |varn=14 |x=0.1069306373 |newn4=14.106930637 |
----- INSIDE TOP of LOOP _N_=1 |i=5 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=5 |varn=15 |x=0.9160557245 |newn5=15.916055724 |
----- INSIDE TOP of LOOP _N_=1 |i=6 |
----- INSIDE BOTTOM of LOOP _N_=1 |i=6 |varn=16 |x=0.0842098724 |newn6=16.084209872 |
-----what is in TESTIT2 -- ONLY 1 OBS, but now have variables NEWN0-NEWN6
-----OUTSIDE of LOOP
newn0=10.113256606 newn1=11.705270167 newn2=12.828789424 newn3=13.305084487 newn4=14.106930637
newn5=15.916055724 newn6=16.084209872 i=7 x=0.0842098724 varn=16 _ERROR_=0 _N_=1
*************************************************
NOTE: The data set WORK.TESTIT2 has 1 observations and 10 variables.
NOTE: DATA statement used (Total process time):
real time 0.09 seconds
cpu time 0.03 seconds
[/pre]