Hi....I am trying to create bar graphs that have both the counts and percentages on the graphs. The problem I am having is the font size on each bar is too small. Is there a way to specifiy the font size or height for the bar labels. Also, I am creating separate bar graphs for each question, is it possible to label the question inside the graph rather than outside the graph and a border. Thanks.
Axis1 style=1 width=1 minor=none label=(height=9pt font="arial/bold" angle=90 "Percent") value=(height=9pt font="arial" "0%" "10%" "20%" "30%" "40%" "50%" "60%" "70%" "80%" "90%" "100%");
Axis2 style=1 width=2 label=(height=9pt font="arial/bold" "Response") value=(height=9pt font="arial");
Axis3 label=(height=9pt font="arial/bold" "Term") value=(height=9pt font="arial");
title;
title1 "PT Survey Data Bar Chart";
footnote;
proc gchart data=Want7;
vbar Response / discrete group=Term type=percent inside=pct outside=freq nolegend g100
coutline=black raxis=axis1 maxis=axis2 gaxis=axis3 woutline=1 patternid=midpoint width=20;
by Question ;
run;
quit;
Output:
Question=My experience with course content and the learning environment. - The course content was interesting.
SGPLOT VBAR can produce a G100 vbar chart. The proc option PCTLEVEL controls how the VBAR PERCENT is computed. The SGPLOT vbar category is term instead of response that is used in GCHART vbar.
Example:
I used the variable name answer instead of response. This was done to help avoid any mindset confusion with the vbar option response=.
The data is pre-counted answers. Small changes would be needed if the plot data set is one row per respondent (i.e. raw/unsummarized).
option DATALABELATTRS= is used to increase the bar data font size.
data have (label="Survey summary count"); question = 'One'; length Term $20 Answer $10; input term & answer & count; if term ne lag(term) then answer_seq=1; else answer_seq+1; datalines; Fall 2018 Disagree 4 Fall 2018 Neutral 36 Fall 2018 Agree 160 Spring 2019 Disagree 6 Spring 2019 Neutral 24 Spring 2019 Agree 70 ; ods html file='vbar.html'; title "Survey chart"; data need; set have; count_as_label = count; * separate var neeed because count is also response=; run; proc sgplot data=need pctlevel=group; by question; vbar term / response=count group=answer groupdisplay=cluster grouporder=data barwidth=0.85 stat=percent datalabel=count_as_label datalabel=answer datalabelattrs=(size=11pt) ; xaxis labelpos=right display=(noticks) ;*tickstyle=inside; yaxis display=(nolabel) values=(0 to 1 by .1) offsetmin=0.07; keylegend / location=inside position=bottom title=""; run; ods _all_ close;
SGPLOT VBAR can produce a G100 vbar chart. The proc option PCTLEVEL controls how the VBAR PERCENT is computed. The SGPLOT vbar category is term instead of response that is used in GCHART vbar.
Example:
I used the variable name answer instead of response. This was done to help avoid any mindset confusion with the vbar option response=.
The data is pre-counted answers. Small changes would be needed if the plot data set is one row per respondent (i.e. raw/unsummarized).
option DATALABELATTRS= is used to increase the bar data font size.
data have (label="Survey summary count"); question = 'One'; length Term $20 Answer $10; input term & answer & count; if term ne lag(term) then answer_seq=1; else answer_seq+1; datalines; Fall 2018 Disagree 4 Fall 2018 Neutral 36 Fall 2018 Agree 160 Spring 2019 Disagree 6 Spring 2019 Neutral 24 Spring 2019 Agree 70 ; ods html file='vbar.html'; title "Survey chart"; data need; set have; count_as_label = count; * separate var neeed because count is also response=; run; proc sgplot data=need pctlevel=group; by question; vbar term / response=count group=answer groupdisplay=cluster grouporder=data barwidth=0.85 stat=percent datalabel=count_as_label datalabel=answer datalabelattrs=(size=11pt) ; xaxis labelpos=right display=(noticks) ;*tickstyle=inside; yaxis display=(nolabel) values=(0 to 1 by .1) offsetmin=0.07; keylegend / location=inside position=bottom title=""; run; ods _all_ close;
Is your value=(height=9pt) not affecting the text size? Have you tried a larger value there?
Yes...I tried a larger and smaller value and nothing would change.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.