data a;
input id $ x $;
cards;
001 a
001 g
003 4
003 g
004 h
;
run;
proc sort data = a out = b(keep = id) nodupkey; by id;run;
%macro test();
data _null_;
set b nobs=n;
call symput(cats('var',_n_),id);
if _n_ = n then do;
call symput('n',n);
stop;
end;
run;
data %do ii = 1 %to &n.;
c_&ii.
%end;;
set a;
select(id);
%do ii = 1 %to &n.;
when (compress("&&var&ii..")) output c_&ii.;
%end;
otherwise;
end;
run;
%mend;
%test();