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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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