Hi Everyone,
I want to create a table that report the number of descrete value for each variables (listed in the name file).
it should look like the table "want"
Since the list of variables I want to create report is 200+ variables, I need to make a code instead of doing it manually.
Thank you for your help.
Merry Christmas and Happy New Year!
HHC
data have;
input var1 var2 var3 var4;
datalines;
1 12 300 4
2 12 500 0
0 12 200 2
0 15 200 2
;run;
data name;
input name $;
datalines;
var1
var2
var3
;run;
data want;
input var1 var2 var3;
datalines;
1 12 300
2 15 500
0 . 200
;run;
data have; input var1 var2 var3 var4; datalines; 1 12 300 4 2 12 500 0 0 12 200 2 0 15 200 2 ;run; data name; input name $; datalines; var1 var2 var3 ; run; data _null_; set name end=last; if _n_=1 then call execute('proc sql;'); call execute(cat('create table want_',strip(_n_),' as select distinct(',name,') as ',name,' from have;')); if last then call execute('quit;'); run; data want; merge want_:; run;
Maybe only part of what you want, the variables are stacked rather than each in their own column.
ods table onewayfreqs=temp;
proc freq data=sashelp.class;
run;
*Format output;
data want;
length variable $32. variable_value $50.;
set temp;
Variable=scan(table, 2);
Variable_Value=strip(trim(vvaluex(variable)));
keep variable variable_value frequency percent cum:;
label variable='Variable'
variable_value='Variable Value';
run;
*Display;
proc print data=want(obs=20) label;
run;
Slight mod from here:
data have; input var1 var2 var3 var4; datalines; 1 12 300 4 2 12 500 0 0 12 200 2 0 15 200 2 ;run; data name; input name $; datalines; var1 var2 var3 ; run; data _null_; set name end=last; if _n_=1 then call execute('proc sql;'); call execute(cat('create table want_',strip(_n_),' as select distinct(',name,') as ',name,' from have;')); if last then call execute('quit;'); run; data want; merge want_:; run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.