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;
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.
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?
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.