BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
Andre
Obsidian | Level 7
Hello,
as the only options available for detail_percent are best or none
you must write it by your own througth an annotate

Andre
deleted_user
Not applicable
Thanks Andre i was thinking on the same lines.
Cynthia_sas
SAS Super FREQ
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]

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 3 replies
  • 3426 views
  • 0 likes
  • 3 in conversation