%macro cnt;
proc sql noprint;
select name into: varlist separated by " " from dictionary.columns
where libname='WORK' and memname='A';
quit;
%let i=1;
%do %until(%scan(&varlist,&i)=%str( ));
proc sql;
create table a&i as
select "%scan(&varlist,&i)" as var, %scan(&varlist,&i) as cat,count(%scan(&varlist,&i)) as n
from a
group by 1,2;
quit;
%let i=%eval(&i+1);
%end;
%let cnt=%sysfunc(count(&varlist,%str( )));
data combine;
set
%do i=1 %to %eval(&cnt+1);
a&i
%end;
;
run;
%mend;
%cnt
data wanted;
set combine;
by notsorted var;
if not first.var then var='';
run;