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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

6 REPLIES 6
ballardw
Super User

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.

snoopy369
Barite | Level 11
Sadly, markercolor doesn't work; I think you're probably right and it just isn't supported yet. (I'm also in M6, about to finally get m7 so perhaps it's upgraded in that, but won't have a chance to test for a while.) Thanks!
GraphGuy
Meteorite | Level 14

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;

 

bar1.png

 

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;

 

bar2.png

 

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;

 

pie.png

 

snoopy369
Barite | Level 11
Thanks for the detailed explanation! I guess that makes sense, but it would be real nice to have more of this stuff exposed to the attribute maps - is it not exposed for a technical reasons, or not a priority compared to other work?
DanH_sas
SAS Super FREQ

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.

snoopy369
Barite | Level 11
Ah - that's interesting to hear, and makes sense. That explains why the terminology is "generic" and not specific to the proc - I had wondered why it wasn't just the exact word ("datalabelattrs" or similar), and that explains it. Still would be nice to have the option but if it's not consistent then I understand! Thanks for the explanation.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1593 views
  • 4 likes
  • 4 in conversation