BookmarkSubscribeRSS Feed
vegan_renegade
Obsidian | Level 7

Hello all, first time poster here. I am successfully getting a pie chart output with proc gchart in SAS 9.4, but I'd like to round the percents to whole numbers, but I cannot find an option to do this within proc gchart from researching online.  The codes and outputs follow below. I am still a rather beginner SAS user, so perhaps there are other ways. Thank you.

 

 

/*Pie chart - Time Living in the US if Born Outside US.*/
title1 'Time Living in the US if Born Outside US';
proc gchart data=cohortb2019_Q2;
pie years_group    /*variable*/ 
/ 
type=freq            /*Statistic being analyzed. In this case, it's counts*/
percent=inside       /*Adds percent inside pie chart*/
radius=25            /*Size of the pie chart*/
woutline=1           /*Size of outline*/
angle=100            /*Angle of the pie chart*/
coutline=white       /*Color of pie lines*/
plabel=
	(height=1.4  /*Size of text*/ 
	 color=black /*Color of text*/
	 font='Georgia/bold') /*Font*/
noheading;           /*Excludes the heading that indicates what variables are being run*/
run;
quit;

 

The output is:

 

gchart5.png

I'd like the percents to be 27%, 18%, etc. (rounded). I also have a frequency table code:

/*Outputs frequencies for country of origin (birth).*/
proc freq data=cohortb2019_Q2;
tables born_abroad country_born /missing;
title 'Born Abroad?';
run;

And the output being:

 

Capture.JPG

4 REPLIES 4
Reeza
Super User
If you can switch to SGPIE there's the statfmt that allows you to specify the format of the variable.
GraphGuy
Meteorite | Level 14

If you're wanting to have complete control over the format of the value shown in a Gchart pie chart, I would recommend pre-calculating your statistic, and then only showing that 1 value on the pie. For example...

 

data summarized;
length country $20;
input my_pct country;
datalines;
.2727 Philippines
.1818 USA
.0909 China
.0909 Eritrea
.0909 Guam
.1818 Mexico
;
run;

 

title1 'Time Living in the US if Born Outside US';
proc gchart data=summarized;
format my_pct percent7.0;
pie country /
type=sum sumvar=my_pct
value=inside
radius=25
woutline=1
angle=100
coutline=white
plabel=(height=1.4 color=black font='Georgia/bold')
noheading;
run;

 

pie.png

vegan_renegade
Obsidian | Level 7

Thank you, I actually tried using a percent format just like you did here, but the problem is it makes my counts disappear in the pie chart (see my original post, it shows the counts). I want the counts to stay.

GraphGuy
Meteorite | Level 14

Yep - that's where the "only showing that 1 value on the pie" caveat comes in. 🙂

 

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