Hello Statadm,
This is a possible solution:
[pre]
data i;
E4CONT=1;
E4_AGE=2;
E4_DATE=3;
run;
%macro a (in=E4, out=E1);
proc SQL;
select COUNT(distinct name) as n into :n
from sashelp.vcolumn
where libname="WORK" and memname="I" and SUBSTR(UPCASE(name),1,2)="&in";
%let n=%TRIM(&n);
select distinct name as names into:n1-:n&n
from sashelp.vcolumn
where libname="WORK" and memname="I" and SUBSTR(UPCASE(name),1,2)="&in";
quit;
data i;
set i;
rename
%do i=1 %to 3;
&&n&i=&out.%SUBSTR(&&n&i,3)
%end;
;
run;
%mend a;
%a(in=E1, out=E5);
[/pre]
Sincerely,
SPR