BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
leonoramillan
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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;

View solution in original post

8 REPLIES 8
SASKiwi
PROC Star

Try adding this:

 

goptions colors=(red yellow green);
leonoramillan
Fluorite | Level 6

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?

SASKiwi
PROC Star

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;
leonoramillan
Fluorite | Level 6

I got this:

Mypie.png

SASKiwi
PROC Star

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;
SASKiwi
PROC Star

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.

leonoramillan
Fluorite | Level 6
Thank you very much SASKiwi. It worked 👌
GraphGuy
Meteorite | Level 14

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;

 

 

pie_color.png

SAS Innovate 2025: Register Now

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!

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
  • 8 replies
  • 5730 views
  • 2 likes
  • 3 in conversation