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
Fluorite | Level 6
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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2791 views
  • 0 likes
  • 3 in conversation