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

Dear All, 

 

I was wondering if there is a way to display only the most frequent categories (let's say, 10) when using PROC FREQ.

proc freq data= sashelp.cars order= freq;
	table make; run;

The code shows the list of car makers with their frequency. But I just would like to display this information for the top 10 carmakers. The below table is what I would like to have. Thanks in advance!

 

Make Frequency Percent Cumulative
Frequency
Cumulative
Percent
Toyota 28 6.54 28 6.54
Chevrolet 27 6.31 55 12.85
Mercedes-Benz 26 6.07 81 18.93
Ford 23 5.37 104 24.30
BMW 20 4.67 124 28.97
Audi 19 4.44 143 33.41
Honda 17 3.97 160 37.38
Nissan 17 3.97 177 41.36
Chrysler 15 3.50 192 44.86
Volkswagen 15 3.50 207 48.36

 

1 ACCEPTED SOLUTION

Accepted Solutions
Watts
SAS Employee

You can use the MAXLEVELS= option in the TABLES statement.

 

proc freq data=sashelp.cars order=freq;
    tables make / maxlevels=10;

 

 

View solution in original post

4 REPLIES 4
ballardw
Super User

One way, make a data set. Then select the observations to print:

proc freq data= sashelp.cars order= freq noprint;
	table make/out=work.carfreq; 
run;

proc print data=work.carfreq(obs=10);
run;
Watts
SAS Employee

You can use the MAXLEVELS= option in the TABLES statement.

 

proc freq data=sashelp.cars order=freq;
    tables make / maxlevels=10;

 

 

mkeintz
PROC Star
Thanks, I was totally ignorant of MAXLEVELS - cool.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Rick_SAS
SAS Super FREQ

You can also use the MAXLEVELS=10 option to create a bar chart that shows the top categories. See "An easy way to make a "Top 10" table and bar chart in SAS."

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 4186 views
  • 7 likes
  • 5 in conversation