Ah, I see. You seem to want to create macro variables in one DATA step program and then you want to do a lookup (from those macro variables) in a second data step program -- based on some value from data in the second data step program.
I'm still not convinced you need a macro %DO loop yet. Consider the following macro program, %PUT_GET.
First, I make 38 macro variables &_NIE1-&_NIE19 and &_AGE1-&_AGE19 -- from the names and ages in SASHELP.CLASS. Next, I have a macro %DO loop write those values to the SAS log. Finally, in a subsequent DATA step in the macro program, I show 3 approaches:
1) Use SYMGET to get the values out of the macro lookup table
2) Use math to get successive values out of the macro lookup table into hardcoded variable names (still with SYMGET)
3) Finally, use 2 ARRAYs inside a DATA step DO loop to make 19 dataset variables to hold name and make 19 dataset variable to hold age (the ARRAY variables are also assigned values with SYMGET.
Each of these approaches uses data in SASHELP.SHOES. Basically, using the STORES variable as an "index" to get some or all of the macro variable values from the macro symbol table. (STORES is just an arbitrary numeric variable that represents the number of stores for an observation in SASHELP.SHOES).
Note how SYMGET can use a DATA step/data set variable as the "index" to retrieve a macro variable value from the macro symbol table. I don't see where your lookup needs a macro %DO loop yet.
This is an older paper that talks about using SYMPUT and SYMGET for lookups:
http://www2.sas.com/proceedings/sugi25/25/cc/25p078.pdf and here's a paper specifically on lookup techniques (not limited to macro techniques):
http://www2.sas.com/proceedings/sugi27/p011-27.pdf
http://www.lexjansen.com/sugi/sugi21/is/127-21.pdf
cynthia
[pre]
%macro put_get;
** First, make macro variables from sashelp.class;
data _null_;
set sashelp.class;
call symput('_nie'||left(put(_n_,2.0)), name);
call symput('_age'||left(put(_n_,2.0)), put(age,2.0));
run;
** Next macro DO loop -- look in log for this output -- what values are in the macro variables?;
%do i = 1 %to 19;
%put i = &i;
%put _nie&i val is &&_nie&i ;
%put _age&i val is &&_age&i ;
%put **** **** **** **** ****;
%end;
** now, arbitrarily use the STORES value from sashelp.shoes;
** to retrieve a value from the macro symbol table;
** using the SYMGET function;
data shoeclass;
set sashelp.shoes;
** stores is a variable whose value can range from;
** 1 to 41 -- since sashelp.class only has 19 obs, we will just;
** use obs with that many stores or less from a few regions. STORES will now be;
** what we use for lookup from the macro symbol table.;
if stores le 19 and
region in ('Canada', 'Pacific');
** Approach 1: lookup only based on stores directly with values assigned into a few variables;
lookup1 = symget('_nie'||left(put(stores,2.0)));
lookup2 = symget('_age'||left(put(stores,2.0)));
** Approach 2: hard-code numbered variables and use math in the SYMGET function;
** to get 2 sets of successive values.;
if stores le 18 then do;
lkup_nm1 = symget('_nie'||left(put(stores,2.0)));
lkup_ag1 = symget('_age'||left(put(stores,2.0)));
lkup_nm2 = symget('_nie'||left(put(stores+1,2.0)));
lkup_ag2 = symget('_age'||left(put(stores+1,2.0)));
end;
** Approach 3: Use an Array and a DATA step DO loop and fill the array;
** using SYMGET -- define array size as max number of possible lookups -- 19;
array nm $8 nm1-nm19;
array ag ag1-ag19;
** now use a data step DO loop;
do ind = stores to 19;
nm(ind) = symget('_nie'||left(put(ind,2.0)));
hold =symget('_age'||left(put(ind,2.0)));
ag(ind) = input(hold,2.0);
end;
run;
%mend put_get;
** Invoke the Macro;
%put_get;
** Examine the output created in the program above;
ods listing close;
ods html file='lookup_macro.html' style=sasweb;
proc report data=work.shoeclass nowd;
title 'Output from all 3 Lookup Approaches';
column region sales stores
('Approach 1' lookup1 lookup2)
('Approach 2' lkup_nm1 lkup_ag1 lkup_nm2 lkup_ag2 )
('Approach 3' nm1 ag1 nm2 ag2 nm3 ag3 nm4 ag4 nm5 ag5 nm6 ag6 nm7 ag7 nm8 ag8
nm9 ag9 nm10 ag10 nm11 ag11 nm12 ag12 nm13 ag13
nm14 ag14 nm15 ag15 nm16 ag16 nm17 ag17 nm18 ag18 nm19 ag19);
run;
ods html close;
title;
[/pre]