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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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