Hello,
I would like to create a 10 variable table with the count/percent/accumulated percent, all of the variables are characters. Please let me know how to approach it, thank you.
proc freq data=sashelp.class noprint; table sex/out=sex(rename=(sex=level)) outcum; table name/out=name(rename=(name=level)) outcum; run; data want; length dsn level $ 100; set sex name indsname=indsname; dsn=indsname; run;
Please post example data (as usual, data step with datalines) and the expected result (dataset or report)
Look at PROC FREQ for starters.
This can help you get started:
https://gist.github.com/statgeek/e0903d269d4a71316a4e
/*This code is an example of how to generate a table with
Variable Name, Variable Value, Frequency, Percent, Cumulative Freq and Cum Pct
No macro's are required
Use Proc Freq to generate the list, list variables in a table statement if only specific variables are desired
Use ODS Table to capture the output and then format the output into a printable table.
*/
*Run frequency for tables;
ods table onewayfreqs=temp;
proc freq data=sashelp.class;
table sex age;
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;
@ybz12003 wrote:
Hello,
I would like to create a 10 variable table with the count/percent/accumulated percent, all of the variables are characters. Please let me know how to approach it, thank you.
I generated a code below, not sure whether it's correct. How to list numbers from highest to the lowest? Thanks.
proc freq data=underly1621_nodup;
tables X1-X10 / out=FreqCount;
run;
proc print data=FreqCount noobs;
title2 'ARI2016-2021 Underlying Condition count table';
run;
@ybz12003 you've been here long enough to know that we don't have your data, we don't know what it looks like, and we don't know what you think may not be correct. How can we help you if we don't know these things? The first response above, from @Kurt_Bremser, makes that pretty clear. You're not going to get much help until you provide the information requested.
It's not correct.
@ybz12003 wrote:
I generated a code below, not sure whether it's correct. How to list numbers from highest to the lowest? Thanks.
proc freq data=underly1621_nodup; tables X1-X10 / out=FreqCount; run; proc print data=FreqCount noobs; title2 'ARI2016-2021 Underlying Condition count table'; run;
@ybz12003 wrote:
I generated a code below, not sure whether it's correct. How to list numbers from highest to the lowest? Thanks.
proc freq data=underly1621_nodup; tables X1-X10 / out=FreqCount; run; proc print data=FreqCount noobs; title2 'ARI2016-2021 Underlying Condition count table'; run;
Which "numbers"? As a minimum the output data set will contain a count and a percent "number". If you X variables are numeric then those would be as well.
And you may want to look very closely at your FreqCount data set. It likely only has the values for X10. Creating output data sets with the Table statement and an OUT= option will only have the results from the last variable in the list on the tables statement. @Reeza in her post showed how to place the results for multiple variables into an output table.
Present something in order: Proc Sort before Proc print.
Proc Freq and the Order=Freq might be appropriate sometimes but we do not know what order you want.
proc freq data=sashelp.class noprint; table sex/out=sex(rename=(sex=level)) outcum; table name/out=name(rename=(name=level)) outcum; run; data want; length dsn level $ 100; set sex name indsname=indsname; dsn=indsname; run;
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.
Ready to level-up your skills? Choose your own adventure.