Hi:
When you use a %DO loop, your loop index becomes a MACRO variable. So in this case, any references to i should be &i;
However, as it says here (and in the documenation):
http://support.sas.com/kb/22/987.html
-You cannot use a MACRO variable reference to retrieve the value of a MACRO
variable in the same program (or step) in which SYMPUT creates that MACRO
variable and assigns it a value.
-You must explicitly use a step boundary statement to force the DATA Step to
execute before referencing the MACRO variable that is created with SYMPUT. The boundary
could be a RUN statement or another DATA or PROC statement.
This means that you CANNOT have the creation of &J and the use of &J in the same DATA step program.
This documentation is quite useful:
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/a000210266.htm
It still is not clear to me what your exact process needs to be. However, consider the program below, which shows 2 new (dataset) variables being created from &I and &J (which are created OUTSIDE the Data step program...&I is created in the %DO loop and &J is created with a %LET). Note how the global macro variables &NEW_I and &NEW_J are available AFTER the Data step program and AFTER the macro program. They would NOT have been available INSIDE the Data step program. Note that you will see the DATASET variables in the PROC PRINT output and you will see the MACRO variables in the TITLE statement and in the %PUT results in the SAS log.
cynthia
[pre]
%macro mymacro;
%global new_i new_j;
%do i=1 %to 3;
%let j=%eval(&i + 10);
** because macro vars I and J are set -outside- the DATA step;
** they can be referenced -inside- the program;
data newset&i;
set sashelp.class;
if _n_ = &i then do;
newvar_i = &i + 10;
newvar_j = &j -10;
call symput('new_i',put(newvar_i,2.0));
call symput('new_j',put(newvar_j,2.0));
output;
end;
run;
** because there is a step boundary after the creation of;
** new_i and new_j macro variables, you can use them;
** after the program is over. Also, because they are GLOBAL;
** macro variables, they are available after the macro stops;
** executing;
ods listing;
proc print data=newset&i;
title "Value of I=&i Value of J=&j at program START";
title2 "NEWVAR_I is &i + 10 = %eval(&i+10)";
title3 "NEWVAR_J is &j - 10 = %eval(&j-10)";
title4 "Inside Macro: new_i = &new_i and new_j = &new_j";
run;
%end;
%mend mymacro;
%mymacro;
%put ************* Look in Log ****************;
%put Outside Macro: new_i = &new_i and new_j = &new_j;
[/pre]