BookmarkSubscribeRSS Feed
suraj747
Fluorite | Level 6

I am trying to make a simple pie chart using the Proc Gchart. However, the data set has two variables and second variable has the value zero. The dataset looks like the below code:

 

data test;
input province $ amount;
datalines;
AA 20
BB 0
;
run

 

The proc gchart code that i am using is :

 

PROC GCHART DATA =work.test;
PIE province / sumvar=amount other=1 legend=outside
midpoints=old
TYPE=SUM
value=none
PERCENT=arrow
slice=arrow
noheading
plabel=(font='albany AMT/bold' h=1.3 color=crimson);

run;

Below is the result of the proc gchart

 

Pie chart.JPG

 

 

The result that i want is that all variables (even with zero value) should be part of pie chart and legend.

 

 

 

 

Thanks

6 REPLIES 6
ballardw
Super User

Any pie chart with a zero area is going to have a lot of difficulty displaying it as part of chart.

 

Likely if you want something such as BB 0% displayed as part of the graph you may need to use some from of annotate. Which may be a lot of work if you actually have multiple 0 or just very small values.

This is one of the reasons why many people prefer to use bar charts instead of pie charts; a 0 length bar is easy to include and label.

 

You might also want to consider moving the more modern SGPLOT or SGPANEL procedures as those are the ones receiving additional features in recent releases.

suraj747
Fluorite | Level 6

Thanks for replying @ballardw.

Any resources or a reference code for SGPLOT or SGPANEL that might help with getting the desired output.

 

Thanks

ballardw
Super User

http://support.sas.com/sassamples/graphgallery/PROC_SGPLOT.html

 

has a number of examples for SGPLOT

 

From what I can guess about your actual data this may be a close-ish example

 

http://support.sas.com/kb/48/123.html

 

The example provides data, code and a view of the graph created

 

https://support.sas.com/en/knowledge-base/graph-samples-gallery.html   many examples of different procedures

 

https://blogs.sas.com/content/graphicallyspeaking/      has many interesting examples of graphs using a variety of techniques

 

as does

http://robslink.com/SAS/

 

 

suraj747
Fluorite | Level 6
Thanks for providing the links @ballardw. These are quite extensive. For my problem, I guess I will have to opt for some shabby way to display the missing content. Is there is any way we can highlight the concern to the folks at SAS so that that can possibly include some kind of fix for future release ?
ballardw
Super User

You can always post suggestions at https://communities.sas.com/t5/SASware-Ballot-Ideas/idb-p/sas_ideas

 

IMHO if the data is missing then anything that makes it appear as though values are actually there is a major error.

For something like a BAR chart you can show a value of 0 or even missing with some knowledge of the options and settings. Pie charts, especially with your implication that you want to show multiple missing categories are going to start looking like there are values there as a sector of any width. Even showing a label of 0 may be interpreted as a value that has been rounded down to some extent. So I would question the use logic of showing categories that are not present with a pie chart other than as something like text saying explicitly that the categories are not represented.

GraphGuy
Meteorite | Level 14

The "other=1" option would group any slice less than 1% into an 'other' slice, and I presume since value of zero is less than 1% of the pie, it is going into 'other' ... and then since the 'other' slice is 0% of the pie, gchart is not showing it.

 

To have this pie slice show up, you could set it to a very small non-zero value (such as .00001) and then use other=0 (so the slice doesn't get lumped into an 'other' slice). I'm not sure it's a good idea to have such a pie ... but this is one way to visually produce what you're asking for 🙂

 

data test;
input province $ amount;
datalines;
AA 20
BB 0.00001
;
run;

PROC GCHART DATA=test;
PIE province / sumvar=amount
angle=90
other=0
legend=outside
midpoints=old
TYPE=SUM
value=none
PERCENT=arrow
slice=arrow
noheading
plabel=(font='albany AMT/bold' h=1.3 color=crimson);
run;

 

zero_pie.png

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 6 replies
  • 3585 views
  • 1 like
  • 3 in conversation