BookmarkSubscribeRSS Feed
sms39
Fluorite | Level 6

Hi all,

 

I am trying to specify pie chart slice colors but keep finding myself at the default colors chosen for me by SAS. I am hoping to correlate charts across distinct data sets, so coordinating colors among the charts would be helpful. There is no auto-recognition of the test in the discreteattrmap, so perhaps that is not feasible for this pie chart, but I will include my attempt below.

Does anyone have any suggestions as to what I am doing wrong? Thank you!

 

/* General Demographics - age groups*/
/* Group 1*/
proc format;
value AgeGrp 1-30 ='Age <30'
30-59 = 'Age 30-59'
60-100 = 'Age >60';
run;

proc freq data=work.analysis_population;
format SC_AGE AgeGrp.;
Table SC_AGE;
Run;

 

proc template;
define statgraph pie;
begingraph;
discreteattrmap name="AgeAttr";
value "Age <30" / fillattrs=(color=green);
value "Age 30-59" / fillattrs=(color=red);
value "Age >60" / fillattrs=(color=blue);
enddiscreteattrmap;


discreteattrvar attrvar=AgeGrp var=SC_AGE attrmap="AgeAttr";
layout region;
piechart category=SC_AGE / start=90 categorydirection=clockwise
datalabelattrs=(size=12) dataskin=matte;
endlayout;
endgraph;
end;
run;

 

 

ods graphics / reset width=6.4in height=4.8in imagemap;

proc sgrender data=WORK.analysis_population template=pie;
format SC_AGE AgeGrp.;
run;

ods graphics / reset;

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20
SuzanneDorinski
Lapis Lazuli | Level 10

I don't use the graph template language, but I was able to use an attribute map data set with several SASHELP data sets.

 

As the log notes, SGPIE is pre-production for SAS 9.4M6.  I tried to control the color for the "Other" slice when using AgeAtStart for the SASHELP.HEART data set, but couldn't get the syntax to work.

 

proc format;
  value AgeGrp 
    1 - 29 ='Age < 30'
    30 - 59 ='Age 30 - 59'
    60 - 100 ='Age 60+'
      ;
run;

data attrmap;
  length ID $ 8 FillColor $ 9 value $ 11;
  infile datalines dlm='|';
  input id $ fillcolor $ value $;
  datalines;
myagegrp|green|Age < 30
myagegrp|red|Age 30 - 59
myagegrp|blue|Age 60+
     ;
run;

ods listing gpath='/folders/myfolders/ODS Graphics/SGPIE'
    style=HTMLBlue;

ods graphics / noborder
               imagename='SGPIE_example_'
               reset=index(1);

proc sgpie data=sashelp.bmimen dattrmap=attrmap;
  pie age / startangle=90 direction=clockwise attrid=myagegrp
            datalabelattrs=(size=12) dataskin=matte;
  format age AgeGrp. ;
  title 'SASHELP.BMIMEN data set';
run;

proc sgpie data=sashelp.class dattrmap=attrmap;
  pie age / startangle=90 direction=clockwise attrid=myagegrp
            datalabelattrs=(size=12) dataskin=matte;
  format age AgeGrp. ;
  title 'SASHELP.CLASS data set';
run;

proc sgpie data=sashelp.heart dattrmap=attrmap;
  pie AgeAtStart / startangle=90 direction=clockwise attrid=myagegrp
                   datalabelattrs=(size=12) dataskin=matte;
  format AgeAtStart AgeGrp. ;
  title 'SASHELP.HEART data set';
  title2 'AgeAtStart';
run;

proc sgpie data=sashelp.heart dattrmap=attrmap;
  pie AgeAtDeath / startangle=90 direction=clockwise attrid=myagegrp
                   datalabelattrs=(size=12) dataskin=matte;
  format AgeAtDeath AgeGrp. ;
  title 'SASHELP.HEART data set';
  title2 'AgeAtDeath';
run;

proc sgpie data=sashelp.heart dattrmap=attrmap;
  pie AgeCHDdiag / startangle=90 direction=clockwise attrid=myagegrp
                   datalabelattrs=(size=12) dataskin=matte;
  format AgeCHDdiag AgeGrp. ;
  title 'SASHELP.HEART data set';
  title2 'AgeCHDdiag';
run;

These are the pie charts:

Pie chart of age in SASHELP.BMIMENPie chart of age in SASHELP.BMIMENPie chart of age in SASHELP.CLASSPie chart of age in SASHELP.CLASSPie chart of AgeAtStart in SASHELP.HEARTPie chart of AgeAtStart in SASHELP.HEARTPie chart of AgeAtDeath in SASHELP.HEARTPie chart of AgeAtDeath in SASHELP.HEARTPie chart of AgeCHDdiag in SASHELP.HEARTPie chart of AgeCHDdiag in SASHELP.HEART

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 1577 views
  • 0 likes
  • 3 in conversation