BookmarkSubscribeRSS Feed
richart
Fluorite | Level 6

I have something like attached. Is there a way to change the y axis to % while keeping the annotated actual count above the bars? (i.e. change response to pct but the 56.5, 62.8 etc above the bars?)

 

Image result for bar graph sas with annotation above bar

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Percent of what? I don't understand how this applies to heights.

--
Paige Miller
richart
Fluorite | Level 6

crude example, shouldn't have used heights... just used it as the visualization. pretend it is count data. Want % each bar contributes to the total count (if the heights were counts)

PaigeMiller
Diamond | Level 26

Okay, if I am understanding the question properly (and I may not be), you can use the VBAR statement in PROC SGPLOT, with the DATALABEL= option and probably other options to achieve this. The formatting of the y-axis can be achieved by the YAXIS command with the VALUESFORMAT= option.

--
Paige Miller
Rick_SAS
SAS Super FREQ

I think you need to pre-summarize the data so that the input data contains a Count for each category. Then you can use STAT=PCT to set the Y axis and use DATALABEL=Count to specify the bar labels:

 

/* create bar chart of counts by age */
proc means data=sashelp.class;
class age;
var height;
output out=ClassSummary N=Count;
run;

proc sgplot data=ClassSummary;
vbar age / freq=Count stat=pct datalabel=Count;
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
  • 326 views
  • 2 likes
  • 3 in conversation