It is MUCH easier to store the generated macro variable name into another macro variable and then use three & to evaluate the macro variable that it names.
%macro a;
%local i k name;
%do i = 1 %to 2;
%let name=&&mem&i.._rcols;
%local &name ;
%let &name=;
%do k=1 %to &&mem&i.vartotal;
%let &name = &&&name, _&k;
%end;
%put &=i|&&mem&i|&=name|&&&name| ;
%end;
%put _local_;
%mend a;
data _null_;
call symput("mem1","ae");
call symput("mem1vartotal","4");
call symput("mem2","cm");
call symput("mem2vartotal","3");
run;
%a;
Results
I=1|ae|NAME=ae_rcols|, _1, _2, _3, _4|
I=2|cm|NAME=cm_rcols|, _1, _2, _3|
A AE_RCOLS , _1, _2, _3, _4
A CM_RCOLS , _1, _2, _3
A I 3
A K 4
A NAME cm_rcols
... View more