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

Good Afternoon, I am looking to set the colors of each individual pice slice based on the catagory value (Alignment).  Is there a means to do or control this.  Below is a example of the code I am utilizing.  Thank you.

PROC TEMPLATE;

DEFINE STATGRAPH PIPEPIE;

BEGINGRAPH;

ENTRYTITLE 'Current Pipeline Distribution';

ENTRYFOOTNOTE ' As of ';

layout region;

piechart category=Alignment response=PERCENT1

/ dataskin=crisp datalabellocation=outside;

endlayout;

endgraph;

end;

run;

 

PROC SGRENDER DATA=WORK.PIPE_PIE1 template=PIPEPIE;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

You can use a discrete attrmap to do it. Here is a simple example:

 

proc template;
define statgraph pie;
begingraph;
discreteattrmap name="gender";
   value "F" / fillattrs=(color=pink);
   value "M" / fillattrs=(color=lightblue);
enddiscreteattrmap;
discreteattrvar attrvar=gender var=sex attrmap="gender";
layout region;
  piechart category=gender response=height;
endlayout;
endgraph;
end;
run;

proc sgrender data=sashelp.class template=pie; run;

The attrmap can also be defined in a data set instead of the template, depending on the SAS version you are using.

 

Hope this helps!

Dan

View solution in original post

3 REPLIES 3
DanH_sas
SAS Super FREQ

You can use a discrete attrmap to do it. Here is a simple example:

 

proc template;
define statgraph pie;
begingraph;
discreteattrmap name="gender";
   value "F" / fillattrs=(color=pink);
   value "M" / fillattrs=(color=lightblue);
enddiscreteattrmap;
discreteattrvar attrvar=gender var=sex attrmap="gender";
layout region;
  piechart category=gender response=height;
endlayout;
endgraph;
end;
run;

proc sgrender data=sashelp.class template=pie; run;

The attrmap can also be defined in a data set instead of the template, depending on the SAS version you are using.

 

Hope this helps!

Dan

BLarson
Obsidian | Level 7

That certainly did.  Thank you very much.  My problem was in the ctagory assignment in the layout region.  You example helped me figure that out.  Thank you again.

kavacs
Calcite | Level 5

Hi,

I'm new both to SAS and SAS communities. I use SAS 9.4.

 

I am trying to plot multiple pie charts on one page under each other and I need all pies and legends to be centered. I managed to do that with GCHART using ORIGIN option in legend and RADIUS option in pie statement. Now the distance between one pie and corresponding legend is always the same (independently of the group format - when the image size is sufficient) and all pies are the same size.

 

Next I needed consistent colors in case one group was missing from data. I searched a lot, but apparently I couldn't find a solution for GCHART. Therefore I used your GTL suggestion and it works well, **bleep**, the graphics even looks better now 🙂

 

BUT I can't fix the distance between the pie and the legend nor the position and size of the pie. Can anyone help me with any of these approaches? Using barcharts is out of the question and I'm really desperate..

 

I attached two pdf files with the situation i described and really hope there is someone who can help me.

Thank you in advance.

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