BookmarkSubscribeRSS Feed
capam
Pyrite | Level 9

Hi,

 

I'd like to display on a single plot using vbar or similar labeling with both percentage and frequency count displayed. I use sas 9.4.

 

Code I have is:

 

proc sgplot data=have noborder;
yaxis label= "Counts";
vbar var/GROUPORDER=ascending stat=percent datalabel;
run;

 

How can I modify it to add counts?

Thanks.

12 REPLIES 12
DanH_sas
SAS Super FREQ

See if this will work for you:

 

proc sgplot data=sashelp.class noborder;
yaxis label= "Counts";
vbar age/GROUPORDER=ascending stat=percent datalabel;
xaxistable age / location=inside stat=freq;
run;

Hope this helps!

Dan

capam
Pyrite | Level 9
Thanks Dan for the quick response.
I tried it and it duplicated the items on the x-axis and did not add a percentage.
capam
capam
Pyrite | Level 9
Sorry, it kept the percentage, but did not add a freq.
DanH_sas
SAS Super FREQ

I get the percent labels on the bars and the freq values in the axis table. What version of SAS 9.4 do you have? Please run this and let me know what the log says:

 

%put &sysvlong;

 

Thanks!
Dan

capam
Pyrite | Level 9
version 7.100.3.5419
capam
Pyrite | Level 9
64 %put &sysvlong;
9.04.01M3P062415
DanH_sas
SAS Super FREQ

In the example, the freq values are along the bottom of the bars. I get this with 9.4m3 as well: They can be also moved to the top of the graph.

 

The SGPlot Procedure

capam
Pyrite | Level 9
In my code it repeats the x axis label, rather than counts as in your example.
DanH_sas
SAS Super FREQ

In that case, just add LABEL="Frequency" to the XAXISTABLE statement (after the "/").

DanH_sas
SAS Super FREQ

Or, are you saying that it just repeats 11, 12 13, 14, 15, and 16?

capam
Pyrite | Level 9
Yes. Thanks for the post on labeling, but that's not my main concern. For some reason it is not displaying the count values only the labels as you stated above.
DanH_sas
SAS Super FREQ

Try this and see if it works for you:

 

In a small datastep, copy your category column to another column (such as age2, in this example.) Use age2 in the XAXISTABLE instead.

 

data class;
set sashelp.class;
age2=age;
run;

proc sgplot data=sashelp.class noborder;
yaxis label= "Counts";
vbar age/GROUPORDER=ascending stat=percent datalabel;
xaxistable age2 / location=inside stat=freq label="Frequency";
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 12 replies
  • 5888 views
  • 1 like
  • 2 in conversation