Dear All,
Can I please seek your help on how to display the percentages in two decimal places inside the bars?
Here I am sharing my code for your information.
Your help would be greatly appreciated.
goptions reset=all gsfmode=replace gsfname=outpng device=png target=png xmax=9 in ymax=5.7 in xpixels=2250 ypixels=1500 htext=1.6pct;
axis1 label=none value=(h=1.5 tick=1 " " tick=2 " " tick=3 " " tick=4 " "
tick=5 " " tick=6 " " tick=7 " " tick=8 " "
tick=9 " " tick=10 " " )
minor=none;
axis3 label=none value=(height=1.5
tick=1 "x1 (&c1.)" tick=2 "x2 (&c2.)"
tick=3 "x3 (&c3.)" tick=4 "x4 (&c4.)" tick=5 "x5 (&c5.)"
tick=6 "x6 (&c6.)" tick=7 "x7 (&c7.)" tick=8 "x8 (&c8.)"
tick=9 "x9 (&c9.)" tick=10 "x10 (&c10.)" )
minor=none;
axis2 label=(h=2 a=90 ' ')
value = (height=2.0 tick=1 '0%' tick=2 '10%' tick=3 '20% ' tick=4 '30%' tick=5 '40%' tick=6 '50%' tick=7 '60%' tick=8 '70%'
tick=9 '80%' tick=10 '90%' tick=11 '100%')
minor=none
length=2.7 in
order=(0 to 100 by 10);
legend1 label= none
value = (height=1.5 j=left "legend 1" "legend 2" "legend 3" "legend 4" "legend 5") mode=protect
position=(bottom outside);
proc gchart data=final;
label flag=" ";
vbar flag / discrete subgroup=subgrp
group=flag g100 nozero
freq=count type=percent
inside=percent width=10
raxis=axis2 maxis=axis3 gaxis=axis1
legend=legend1 width=7 gspace=1 ;
run;
quit;
You might try INSIDE=SUBPCT
I never really liked letting GCHART calculate percentages as I was always having to fiddle something.
And might be time to move to Proc SGPLOT.
No data, a slew of macro variables with no idea what they might be means we can't test any code.
This example, very slightly modified from the Proc GChart documentation (hint) shows percentages to 2 decimals:
data totals; length dept $ 7 site $ 8; input dept site quarter sales; datalines; Parts Sydney 1 7043.97 Parts Atlanta 1 8225.26 Tools Paris 4 1775.74 Tools Atlanta 4 3424.19 Repairs Sydney 2 5543.97 Repairs Paris 3 6914.25 ; title1 "Total Sales by Site"; axis1 label=none offset=(10,8); axis2 label=none order=(0 to 20000 by 5000) minor=none offset=(,0); legend1 label=none shape=bar(.15in,.15in) cborder=black; proc gchart data=totals; format sales dollar8.; vbar site / sumvar=sales subgroup=dept inside=subpct outside=sum width=9 space=7 maxis=axis1 raxis=axis2 cframe=white autoref cref=gray legend=legend1; run; quit;title;
Again, you have not actual option that controls the format of the displayed values, the procedure is doing that.
Hi @ballardw. Thank you for your quick response.
We have tried sgplot and are able to get the two decimal places in every segments of the bars.
However, we are having another problem now.
How do we fully utilize the empty area(green highlighted) between the chart and legend?
The legend will not even show if we increase either height, thickness or valueattrs=(size=7pt).
Thanks a lot.
ods graphics on / width=60 in height=45 in noborder;
Proc sgplot data=temp noautolegend pad=(top=1%);
vbar flag / group=subgrp response=percent seglabel seglabelformat=f6.2 grouporder=data;
legenditem type=line name="0" / lineattrs=(pattern=solid thickness=3) lineattrs=GraphData1 label="Legend 1";
legenditem type=line name="1" / lineattrs=(pattern=solid thickness=3) lineattrs=GraphData2 label="Legend 2";
legenditem type=line name="2" / lineattrs=(pattern=solid thickness=3) lineattrs=GraphData3 label="Legend 3";
legenditem type=line name="3" / lineattrs=(pattern=solid thickness=3) lineattrs=GraphData4 label="Legend 4";
.......... up to
legenditem type=line name="8" / lineattrs=(pattern=solid thickness=3) lineattrs=GraphData8 label="Legend 8";
keylegend "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" / location=outside position=bottomleft
title=" " across=3 down=3 valueattrs=(size=7pt) fillaspect=golden linelength=20 noborder;
xaxis label=" " values=(1,2,3,4,5,6,7,8,9,10) valueattrs=(size=7pt)
valuesdisplay=(
"1st (&c1.)"
"2nd (&c2.)"
"3rd (&c3.)"
"4th (&c4.)"
"5th (&c5.)"
"6th (&c6.)"
"7th (&c7.)"
"8th (&c8.)"
"9th (&c9.)"
"10th (&c10.)");
yaxis label=" "
values = (0 to 100 by 10) valuesdisplay=("0%" "10%" "20%" "30%" "40%" "50%" "60%" "70%" "80%" "90%" "100%");
run;
I managed to get rid of the blank area after following what this post has advised https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-creates-too-much-blank-space/td-p/19...
However, the legend entries are small.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.