Data visualization with SAS programming

Color Pie Slices

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Color Pie Slices

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;


Accepted Solutions
Solution
‎04-11-2016 08:39 AM
SAS Super FREQ
Posts: 864

Re: Color Pie Slices

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


All Replies
Solution
‎04-11-2016 08:39 AM
SAS Super FREQ
Posts: 864

Re: Color Pie Slices

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

Contributor
Posts: 26

Re: Color Pie Slices

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.

New Contributor
Posts: 3

Re: Color Pie Slices

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 Smiley Happy

 

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.

Post a Question
Discussion Stats
  • 3 replies
  • 442 views
  • 1 like
  • 3 in conversation