BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tburus
Obsidian | Level 7

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:

plot.png

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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?

View solution in original post

7 REPLIES 7
ghosh
Barite | Level 11
proc sgrender data=viz_dx_pct
	template = rio_pie;
  format wgt_pct 5.1;
run;

Without any data I am just guessing

tburus
Obsidian | Level 7

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

ballardw
Super User

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
Obsidian | Level 7
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.
ballardw
Super User

@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
Obsidian | Level 7
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!
ballardw
Super User

@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. 

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 1718 views
  • 0 likes
  • 3 in conversation