Hey guys
I am trying to do a Pie figure with SAS on demand.
How do I get a pie with the right color? I mean, a pie showing the green, when the color of my category variable is green, red when the color is red, etc. I have tried the code below, but it doesn´t work.
Thank you in advance for your help 🙂
/*Pie chart*/
Data mydata;
Input Color $ Quantity;
Datalines;
Red 10
Yellow 40
Green 50
;
run;
title1'colors of my pie';
pattern1 color=red;
pattern2 color=yellow;
pattern3 color=green;
title1 'My pie';
proc gchart data=mydata;
pie color/ type=sum sumvar=Quantity noheader slice=outside value=inside;
run;
This gets the order right for me:
Data mydata;
Input Color $ Quantity;
Datalines;
Red 10
Yellow 40
Green 50
;
run;
title1'colors of my pie';
goptions colors=(red yellow green);
pattern1 value = solid;
title1 'My pie';
proc gchart data=mydata;
pie color/ type=sum sumvar=Quantity noheader slice=outside value=inside
midpoints = 'Red' 'Yellow' 'Green';
run;
Try adding this:
goptions colors=(red yellow green);
Thank you SASKiwi. I tried both
goptions colors=(red yellow green);
And
goptions colors=(green yellow yellow);
The first option shows the red, yellow and green colors, but not in the desired match. The second one matched the colors. BUT, how can I program (ex-ante) a specific observation of the category with a color? Options colors=( ) seems to work randomly?
OK, I think I've got it now. Pattern1 sets the fill, the colors then cycle through the 3 available.
goptions colors=(red yellow green);
pattern1 value = solid;
I got this:
This gets the order right for me:
Data mydata;
Input Color $ Quantity;
Datalines;
Red 10
Yellow 40
Green 50
;
run;
title1'colors of my pie';
goptions colors=(red yellow green);
pattern1 value = solid;
title1 'My pie';
proc gchart data=mydata;
pie color/ type=sum sumvar=Quantity noheader slice=outside value=inside
midpoints = 'Red' 'Yellow' 'Green';
run;
The full answer is the slices print in alphabetic order regardless of your colour list. The MIDPOINTS option changes the slice order to match the colour order you want.
Here's a slightly different way of doing it - changing the order of the colors in the pattern statements, to match the alphabetical order of the colors (or whatever variable you're using for the slices).
goptions xpixels=500 ypixels=500;
goptions htitle=14pt htext=11pt ftext='albany amt/bold';
Data mydata;
Input Color $ Quantity;
Datalines;
Red 10
Yellow 40
Green 50
;
run;
title1'colors of my pie';
pattern1 color=green;
pattern2 color=red;
pattern3 color=yellow;
title1 'My pie';
proc gchart data=mydata;
pie color/ type=sum sumvar=Quantity noheader slice=outside value=inside;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.