thanks bobguy. Here is the example:
assume I have macro variables L1 L2 L3, I need to get the fourth macro variable named A(or what else) and its content must be "L1 L2 L3".
assume I have L1 L2, then I need A = "L1 L2". ... (w/o "")
assume I have L1 L2 L3 L4, then I need A = "L1 L2 L3 L4". ... (w/o "")
The purpose to get this combo is to use in the proc template like:
proc template;
mvar L1 L2 L3 L4...; *and I would like to use one macro viriable instead of L1-Ln because the n is unknown;
proc sql noprint;select name into:del separated by ' ' from sashelp.vmacro where name like 'T%';quit;
%put &del;
%SYMDEL &del;
%let t1=a;%let t2=b;%let t3=c;
proc sql noprint;select count(*) into:n from sashelp.vmacro where name like 'T%';quit;
%put &n;
data a;
do i=1 to &n;
x="&T"||left(i);
output;
end;
run;
proc sql noprint;select x into:x separated by ' ' from a;quit;
%put &x;
Here is a solution. Assume you know the prefix of a list of macro variables.
proc sql noprint;
select name into : vlist separated by ' '
from dictionary.macros
where scope='GLOBAL' and (name like 'L%' or name like 'W%')
order by 1
;
quit;
%SYMDEL &vlist;
%put _all_;
***create some macro variables***;
data _null_;
n=ceil(10*ranuni(-1));
do i=1 to n;
call symputx(catt('L',i), i);
end;
n=ceil(10*ranuni(-1));
do i=1 to n;
call symputx(catt('W',i), i);
end;
run;
***make a variable w/ prefix into a list;
proc sql noprint;
select name into : vlistL separated by ' '
from dictionary.macros
where scope='GLOBAL' and name like 'L%'
order by 1
;
quit;
%put >>>>&vlistL<<<<;
***make a variable w/ prefix into a list;
proc sql noprint;
select name into : vlistW separated by ' '
from dictionary.macros
where scope='GLOBAL' and name like 'W%'
order by 1
;
quit;