Hi Everyone,
I want to run proc freq to create a table with each column reporting frequency of each variable in the original dataset.
My original data variables only take value 1, 2 ,3. So it will be quite convenient to get that summary table since it only have 3 row (1,2,3)
I guess there should be a way to do it rather than getting table one by one and combine them with proc sql.
The output should be in the format:
value var1 var2 var3
1
2
3
Thank you for your help.
HHC
data have;
input var1 var2 var3
datalines;
1 1 1
2 1 2
3 1 2
1 2 3
;run;
It might take a little reshaping of your data, but it's not lengthy.
data reshape;
set have;
array vars {5} var1-var5;
do _i_=1 to 5;
varname = vname(vars{_i_});
value = vars{_i_};
output;
end;
keep varname value;
run;
proc tabulate data=reshape;
class varname value;
tables value, varname * N=' ' * f=12.;
run;
Personally, I might prefer one variable per row instead of one per column, such as (all else remaining the same):
tables varname, N * value=' ' * f=12. PCTN <value> * value=' ' ;
Good luck.
proc tabulate will do that to that to a destination, but not sure what the output tables look like.
What do you want the output to look like? summary for values Var1,2,3 stacked vertically? horizontally? row headings of 1,2,3 with a column count for each of your variables?
Lots of ways to combine frequency counts but what you want for a final product will affect the approach.
It might take a little reshaping of your data, but it's not lengthy.
data reshape;
set have;
array vars {5} var1-var5;
do _i_=1 to 5;
varname = vname(vars{_i_});
value = vars{_i_};
output;
end;
keep varname value;
run;
proc tabulate data=reshape;
class varname value;
tables value, varname * N=' ' * f=12.;
run;
Personally, I might prefer one variable per row instead of one per column, such as (all else remaining the same):
tables varname, N * value=' ' * f=12. PCTN <value> * value=' ' ;
Good luck.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.