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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.