Quartz | Level 8

## Display 10 most frequent categories in PROC FREQ?

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
SAS Employee

## Re: Display 10 most frequent categories in PROC FREQ?

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

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

4 REPLIES 4
Super User

## Re: Display 10 most frequent categories in PROC FREQ?

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;```
SAS Employee

## Re: Display 10 most frequent categories in PROC FREQ?

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

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

PROC Star

## Re: Display 10 most frequent categories in PROC FREQ?

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

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

## Re: Display 10 most frequent categories in PROC 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."

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