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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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