BookmarkSubscribeRSS Feed
Helle
Calcite | Level 5
Hi,

How can I use proc gchart display the five most frequent values in a data set? From running proc freq, I know that these are the five most frequent values:

Value Count
-1000.00 157
-2000.00 156
-3000.00 155
-4000.00 120
-10000.00 110

I have searched the forums and the web for help but cannot seem to come up with the right combination of search terms to find an answer so I hope that someone in here can help me.

Thanks,

Helle
4 REPLIES 4
GraphGuy
Meteorite | Level 14
Something like this?

data foo;
input value count;
datalines;
-1000.00 157
-2000.00 156
-3000.00 155
-4000.00 120
-10000.00 110
;
run;
proc gchart data=foo;
vbar value / discrete type=sum sumvar=count;
run;
DanH_sas
SAS Super FREQ
Hey,

The way I would approach this is to use PROC SUMMARY to summarize the data based on frequency, use PROC SORT to sort the result by descending frequency, and use PROC GCHART to display the first N bars that I want to see (using OBS=). The simple example below charts the 3 most frequent values.

[pre]
proc summary data=sashelp.class nway;
class age;
output out=agefreq;
run;

proc sort data=agefreq; by descending _freq_; run;

proc gchart data=agefreq (obs=3);
vbar age / sumvar=_freq_ outside=sum discrete;
run;
[/pre]

Hope this helps!
Dan
Helle
Calcite | Level 5
Hi Dan and Robert,

Thanks a lot for your suggetions - they both do the job 🙂

Best regards,

Helle
Bill
Quartz | Level 8
Or, if you have SAS/QC, use

proc pareto.
hbar variable/maxncat=5;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 830 views
  • 0 likes
  • 4 in conversation