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
Opal | Level 21

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
Opal | Level 21

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
Opal | Level 21

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
Opal | Level 21

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
Opal | Level 21

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 4303 views
  • 2 likes
  • 3 in conversation