I the following code I am trying to create a dynamic variable name and use it later in the code, but it isn't fully resolving. please see the last few lines. I would like the put statement macro variable &&mem&i.._rcols to output the same info that is in &xx. I have also tried a data _null_ with a call symput to create the varialbe.
%macro a;
Data _null_;
call symput("mem1","ae");
call symput("mem1vartotal","4");
call symput("mem2","cm");
call symput("mem2vartotal","3");
run;
%do i = 1 %to 2;
%let x = 0;
%do v = 1 %to &&mem&i.vartotal;
%let x = %eval(&x + 1);
%end;
%let &&mem&i.._rcols = %str();
%let xx=%str();
%do k=1 %to &x;
%let xx = %str(&xx, _&k);
%end;
%let &&mem&i.._rcols = %str(&xx);
%put &&mem&i &&mem&i.._rcols &xx ;
%end;
%mend a;
%a;
thank you very much, I Stopped at 4 &.
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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.