BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

Hello, I am trying to use GTL to make a template for a series of pie charts (I know, I know) that are needed for my org. I am trying to use the DISCRETEATTRMAP statement to ensure that certain levels retain the same colors in the pie chart. (People will be viewing lots of these, so I need consistency across charts). The variables in my data set are numeric, and I am using a format to bin them into categories. The desired output is a pie chart with wedges, but this code is making concentric circles and is not applying the colors.

 

I have read the documentation that I can find but am still stumped about where I'm going wrong. If I remove the GROUP statement, I get a pie chart with wedges, but not with the correct colors. Any tips would be appreciated!

 

data test;
input x @@;
datalines;
1 2 2 3 3 3 4 4 4 4 6 6 6 6 6 6 6 7 7 7 5 5 4 4 3 3 
;
run;


** Load the binning format ;
proc format;
  value bin
  1 = 'Never'
  2 = 'Once or Twice'
  3 - 7 = 'Multiple Times'
  ;

proc template;
   define statgraph pie2;
      begingraph;
	     entrytitle "Overall";
		 discreteattrmap name='colors' /ignorecase=true;  ** This is where things are going wrong. ;
                    value 'Never' / fillattrs= (color=green) ;
                    value 'Once or Twice' / fillattrs= (color=yellow) ;
                    value 'Multiple Times'/ fillattrs= (color=red);
                  enddiscreteattrmap ;
		     discreteattrvar attrvar=classfill var=x attrmap='colors';
	     layout region;
            piechart category = x /
	    stat = pct
            datalabellocation = inside
            categorydirection = clockwise
            start = 180 
            name = 'pie'
  	    group = classfill;
            discretelegend 'pie' 
            ;
         endlayout;
      endgraph;
   end;
run;
proc sgrender data = test 
            template = pie2;
			format x bin.;  
run;
1 ACCEPTED SOLUTION

Accepted Solutions
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

Removing group was the first step. I also needed to change the attrvar= to attrvar=x. Thanks!

 

proc template;
   define statgraph pie4;
      begingraph;
	     entrytitle "Overall";
		 discreteattrmap name='colors' /ignorecase=true;  ** This is where things are going wrong. ;
   value 'Never' / fillattrs= (color=green) ;
   value 'Once or Twice' / fillattrs= (color=yellow) ;
   value 'Multiple Times'/ fillattrs= (color=red);
         enddiscreteattrmap ;
		 discreteattrvar attrvar=x var=x attrmap='colors';
	     layout region;
            piechart category = x /
			stat = pct
            datalabellocation = inside
            categorydirection = clockwise
            start = 180 
            name = 'pie'
  			;
            discretelegend 'pie' 
            ;
         endlayout;
      endgraph;
   end;
run;
proc sgrender data = test 
            template = pie4;
			format x bin.;  
run;

View solution in original post

3 REPLIES 3
ballardw
Super User

The

group = classfill

is what makes the concentric rings.

Try removing it and see if the result is as expected.

svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

When I remove it, I get the wedges, but not the desired colors. It's as if I can't get the format to be picked up by the attribute values.

SGRender30.png

svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

Removing group was the first step. I also needed to change the attrvar= to attrvar=x. Thanks!

 

proc template;
   define statgraph pie4;
      begingraph;
	     entrytitle "Overall";
		 discreteattrmap name='colors' /ignorecase=true;  ** This is where things are going wrong. ;
   value 'Never' / fillattrs= (color=green) ;
   value 'Once or Twice' / fillattrs= (color=yellow) ;
   value 'Multiple Times'/ fillattrs= (color=red);
         enddiscreteattrmap ;
		 discreteattrvar attrvar=x var=x attrmap='colors';
	     layout region;
            piechart category = x /
			stat = pct
            datalabellocation = inside
            categorydirection = clockwise
            start = 180 
            name = 'pie'
  			;
            discretelegend 'pie' 
            ;
         endlayout;
      endgraph;
   end;
run;
proc sgrender data = test 
            template = pie4;
			format x bin.;  
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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