Here is my SQL solution.
/* Create sample data for demonstration */
data have;
call streaminit(27182818);
array a[5] Q17_test Q17_new Q17_tmp Q17_abc Q17_314;
do i=1 to 51;
do _n_=1 to dim(a);
a[_n_]=rand('integer',9);
end;
output;
end;
run;
data _null_;
set sashelp.vcolumn(where=(libname='WORK' and memname='HAVE' and upcase(name)=:'Q17_')) end=last;
if _n_=1 then call execute('proc sql;');
call execute(cat('create table stats_',strip(name),' as select ',name,',count(*) as count from have group by ',name,';'));
if last then call execute('quit;');
run;
... View more