BookmarkSubscribeRSS Feed
tburus
Obsidian | Level 7

I have created a template for a pie chart and would like to control the format of the data label. Currently, the data label is reporting the percent to two decimal places, but I'd like to change this to one.

 

Code:

proc template;
define statgraph top5pie;
begingraph / datacolors=(&Dblue &Dgray &Dblack &Dblue2 &Dgray2);
layout region;
	piechart category = interest response = pct /
	datalabellocation = inside
	datalabelcontent=(percent)
	datalabelattrs = (family='Arial/bold' weight=bold size=10pt color=&Dgold.)
	categorydirection = clockwise
	dataskin = crisp
	start = 180 name = 'pie'
	otherslice=true
  	othersliceopts=(type=percent percent=10 label="Others (<10% Each)" fillattrs=(color=&Dtan));
	discretelegend 'pie' /
	title = ''
	titleattrs = (family='Arial' size=12pt)
	itemsize=(fillheight=big)
	border = false;
endlayout;
endgraph;
end;
run;
2 REPLIES 2
ballardw
Super User

Quite often assigning a format in the SGRENDER for the variable involved can address such issues.

Pseudocode since you didn't provide an example your call:

 

Proc sgrender data=have template=yourtemplate;
   format Plotvar formatname.;
run;

Where formatname is an appropriate format for the value, maybe percent8.1 or f5.1.

 

And worst it takes a minute or two to test this approach. At best it does what you want.

tburus
Obsidian | Level 7

I tried using `format` after my SGRender call, but didn't get the desired results.

 

proc sgrender data=viz_body_pct(where=(event_type=1))
	template = top5pie;
    format pct mypcta.;
run;

In the documentation it says that the STAT= option when using a response variable (which is `pct`) is SUM. Is there a way to format the SUM?

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1465 views
  • 0 likes
  • 2 in conversation