Is it possible in SGPIE to use a dynamic data label text color? If so, what is the right variable name?
For example:
data attrmap;
set sashelp.class;
if sex='M' then textcolor='blue';
else textcolor='pink';
fillcolor='orange';
id = 'mycolors';
value = name;
keep id value textcolor fillcolor;
run;
proc sgpie data=sashelp.class dattrmap=attrmap;
pie name/attrid=mycolors;
run;
I know that the attribute map is "working" for the rows since the fillcolor is changing, but the textcolor won't change, and I have tried everything I can - textcolor, datalabeltextcolor, datalabelattrs with 'color=blue' - but can't seem to find the option (or, it's not possible?). Don't really want to go the SGANNO route as suggested on a somewhat similar post, so perhaps it's just not possible... Thanks!
The documentation at https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n04wp1wciaqxtdn10763lgnuj5dh.htm shows SGPIE is still preproduction so likely has not added in all the features you would like. The Styleattrs statement only shows BACKCOLOR ,background outside the pie, and DATACOLORS as options. So likely what you want for other text has not been implemented.
Just for giggles I might try the MARKERCOLOR option if you haven't tried that yet. It sounds like the only one you may not have tried.
The documentation at https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n04wp1wciaqxtdn10763lgnuj5dh.htm shows SGPIE is still preproduction so likely has not added in all the features you would like. The Styleattrs statement only shows BACKCOLOR ,background outside the pie, and DATACOLORS as options. So likely what you want for other text has not been implemented.
Just for giggles I might try the MARKERCOLOR option if you haven't tried that yet. It sounds like the only one you may not have tried.
Here's a little more information ...
Using this attribute map:
data attrmap;
id = 'mycolors';
value='M'; fillcolor='lightblue'; textcolor='blue'; output;
value='F'; fillcolor='pink'; textcolor='red'; output;
run;
Let's first step back and take a look at a sgplot bar chart. The attribute map controls the bar segment colors, but if I just use the automatic 'datalabel' option on the vbarparm statement, the textcolor from the attrmap does not have an effect.
title "sgplot vbarparm with datalabel";
proc sgplot data=sashelp.class noautolegend dattrmap=attrmap;
vbarparm category=name response=height/group=sex attrid=mycolors
datalabel=height groupdisplay=cluster;
run;
However, if I add a custom text statement in which I can specify an attrid and group to specifically associate with the text, then the attribute map can control the color of the text.
title "sgplot vbarparm with 'text' statement";
proc sgplot data=sashelp.class noautolegend dattrmap=attrmap;
vbarparm category=name response=height/datalabel group=sex attrid=mycolors;
text x=name y=height text=height / position=top group=sex attrid=mycolors;
run;
Since sgpie does not have a text statement, and only has the automatic labels, it is consistent (with bar charts) that the pie slice color is controlled by the attrmap, but the text would not be controlled by the attrmap:
title "sgpie";
proc sgpie data=sashelp.class noautolegend dattrmap=attrmap;
pie sex / attrid=mycolors;
run;
For the record, attribute maps do support a TEXTCOLOR column, but it is used for AXISTABLEs -- not data labels. One possible issue with supporting TEXTCOLOR for data labels is that the map could be set up with text color for one purpose (such as axis tables) but then accidentally get applied to inside data labels of a bar or pie in another part of the report, causing them to be difficult to see. You would have to create a duplicate map, minus the TEXTCOLOR, to work around that issue. One of the main ideas behind attribute maps is that you can define them once to create a standard look for your data and use them for all of your graphs in the report.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.