I am rendering a concentric pie chart using PROC SGRENDER with a PIECHART template. I would like to format the percentages reported down to whole numbers, but can't seem to find a way to get it to do anything but report two decimal places.
proc template;
define statgraph rio_pie;
begingraph / designheight=4in datacolors=(&rgreen &rblue &rbronze &rgreen2 &rblue2 &rbronze2 &rgreen3 &rblue3);
layout region;
piechart category = interest response = wgt_pct / group=type
datalabellocation = inside
datalabelcontent = (percent)
datalabelattrs = (family='Arial' weight=bold size=7.5pt color=&Dgold.)
grouplabelopts = (label=None location=right)
groupgap = 7
otherslice=FALSE
categorydirection = clockwise
dataskin = crisp
start = 90 name = 'pie';
discretelegend 'pie' /
title = ''
titleattrs = (family='Arial' size=11pt)
valueattrs = (family='Arial' size=11pt)
itemsize=(fillheight=big)
border = false
displayclipped=TRUE;
endlayout;
endgraph;
end;
run;
proc sgrender data=viz_dx_pct
template = rio_pie;
run;
Result:
@tburus wrote:
Thanks. I did do the calculation myself (that's why the template has RESPONSE=WGT_PCT in it). Funny thing is, no matter how I leave the calculation or format it beforehand, PROC SGRENDER always spits out percentages with two decimal places. This is not the only weird thing I've had this PROC do. It overrides a lot of things if you're not careful. I'm just not sure how to get under the hood and change it.
If wgt_pct is calculated to be the desired percent I would be very tempted to try changing the
datalabelcontent = (percent)
to
datalabelcontent = (response)
and then try the format assignment to the variable.
The datalabelcontent seems to have some interesting relationship with the STAT= option, and since you didn't provide a STAT= option it seems that the stat should be sum. Which the documentation at https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=grstatgraph&docsetTarget=... seems to imply the datalabelcontent should not have any affect with the percent option.
Do the displayed numbers agree with your expectation?
proc sgrender data=viz_dx_pct
template = rio_pie;
format wgt_pct 5.1;
run;
Without any data I am just guessing
This doesn't do anything to it. I feel like FORMAT option on PROC SGRENDER doesn't do anything here. The data being used for the response is a decimal with format PERCENT8.1, but PROC SGRENDER always displays with two decimal places. I feel like this has something to do with the parent style, but I can't seem to find a parent style controlling STATGRAPH PIECHART
For what it may be worth, back in the days before the statistical graph procedures I found that anytime I wanted any formatted correctly on a pie chart I had to summarize the data myself and reference the values. The calculated by the procedure statistics other than FREQ, like percentages, were always a pain to deal with.
@tburus wrote:
Thanks. I did do the calculation myself (that's why the template has RESPONSE=WGT_PCT in it). Funny thing is, no matter how I leave the calculation or format it beforehand, PROC SGRENDER always spits out percentages with two decimal places. This is not the only weird thing I've had this PROC do. It overrides a lot of things if you're not careful. I'm just not sure how to get under the hood and change it.
If wgt_pct is calculated to be the desired percent I would be very tempted to try changing the
datalabelcontent = (percent)
to
datalabelcontent = (response)
and then try the format assignment to the variable.
The datalabelcontent seems to have some interesting relationship with the STAT= option, and since you didn't provide a STAT= option it seems that the stat should be sum. Which the documentation at https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=grstatgraph&docsetTarget=... seems to imply the datalabelcontent should not have any affect with the percent option.
Do the displayed numbers agree with your expectation?
@tburus wrote:
You deserve a special badge by your name for this solution. You have answered a question that has burdened me for months. In previous reports we've just dealt with it, but in this one the pie slices were too small to fit all those decimals nicely, and the fit policy dropped more than we were comfortable with. This worked perfectly!
I am glad you didn't get to such small slices you need an annotate data set with arrows connecting values to minuscule slices to display a label value. I've done that, again back with Gchart, and it was so painful I've essentially wiped my memory of such things.
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.