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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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