Data visualization with SAS programming

Format percentage values in PIE chart

Reply
N/A
Posts: 0

Format percentage values in PIE chart

How do i format percetage values in a pie chart produced using gchart procedure.

I need to format the percentage value of each pie with one decimal place.I found "detail_percent" option, but could not achieve much success with that.


Thanks,
karthik
Super Contributor
Posts: 273

Re: Format percentage values in PIE chart

Hello,
as the only options available for detail_percent are best or none
you must write it by your own througth an annotate

Andre
N/A
Posts: 0

Re: Format percentage values in PIE chart

Thanks Andre i was thinking on the same lines.
SAS Super FREQ
Posts: 8,646

Re: Format percentage values in PIE chart

Hi:
One way, without using ANNOTATE to format the percent, is to "precalculate" the percent and either use a PERCENT format to round to one decimal place or multiply your precalculated percent by 100 and then use a PICTURE format. This means that you will need to use the SUMVAR= option instead of TYPE=PERCENT.

See the code below, which uses a dataset created by PROC REPORT (although you could have used other procedures) from SASHELP.CLASS.

cynthia
[pre]
title;
ods listing;

proc report data=sashelp.class nowd out=work.ageout;
column age n pctn mypct;
define age /group 'Age';
define n / 'Count';
define pctn / 'Percent';
define mypct/computed;
compute mypct;
mypct = round(100*pctn,.1);
endcomp;
run;

proc print data=work.ageout;
run;

proc gchart data=ageout;
Title '1) Use WORK.AGEOUT, PCTN var, PERCENT Format and NOHEADING option';
pie age / discrete type=sum sumvar=pctn noheading;
format pctn percent8.1;
run;
quit;

proc format;
picture mypc low-high="009.9%";
run;

proc gchart data=ageout;
Title '2) Use WORK.AGEOUT, MYPCT var, Picture Format and NOHEADING option';
pie age / discrete type=sum sumvar=mypct noheading;
format mypct mypc.;
run;
quit;

** Original Using SASHELP.CLASS;
proc gchart data=sashelp.class;
title '3) Use SASHELP.CLASS, TYPE=PERCENT, Compare to Previous';
pie age / discrete type=percent noheading;
run;
quit;[/pre]
Post a Question
Discussion Stats
  • 3 replies
  • 981 views
  • 0 likes
  • 3 in conversation