- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I have a massive output of a proc freq of a variable in which I want to only limit to the top 5. How do I set up the code? I used this and it seemed to not work:
proc freq data=janfeb.jfgmi order=freq rowlimit=5;
table finalicd10;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SAS has to count every observation, to know what belongs in the highest 5. So you might as well count them all:
proc freq data=jabfeb order=freq;
tables finalicd10 / noprint out=counts;
run;
By creating a SAS data set instead of printing the table, you now have choices. The simplest:
data want;
set counts (obs=5);
run;
However, if the 5th highest count also appears as the 6th or 7th highest count, you lose the ties. You could instead continue with:
data want;
set counts;
by descending count;
if first.count and _n_ > 5 then stop;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can also use the method that Astounding mentions to graph the top categories. See "Create a bar chart with only a few categories."
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use SQL instead . proc sql outobs=5; select air,count(*) as count from sashelp.air group by air order by count desc; quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This works! Thanks. How do I title a proc sql statement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You mean add a title or lable ?
title 'xxxxxxx';
proc sql outobs=5;
select air,count(*) as count label='xxxxx'
from sashelp.air
group by air
order by count desc;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
##- Please type your reply above this line. Simple formatting, no
attachments. -##
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so much for this code it is very helpful! How would you go about formatting a table like this. I tried using PROC TABULATE to rename the row headers etc. but I don't know how to point the PROC TAB at the new table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Once you assign a label to a variable, proc tabulate would print the label.
like:
options label;
proc tabulate .......
And can start a brand new session to let other know your Q,and maybe others have a better idea.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc freq data=janfeb.jfgmi ORDER=FREQ;
tables make / maxlevels=5 Plots=FreqPlot;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I just stumbled upon this answer and it is by far the simplest solution, thank you so much!