BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

8 REPLIES 8
Reeza
Super User

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.


 

ybz12003
Rhodochrosite | Level 12

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;

 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Reeza
Super User

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;

 


 

ballardw
Super User

@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.

Ksharp
Super User
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;
ybz12003
Rhodochrosite | Level 12
Thanks for your help, though I have figured out some functions I could use from previous questions.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1521 views
  • 1 like
  • 6 in conversation