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

This is an example of what I have using sashelp:

 

data myattrs;
length value fillcolor $12;
show='AttrMap';
id="jrc_ID";
value=11; fillcolor='red'; output;
value=12; fillcolor='yellow'; output;
value=13; fillcolor='green'; output;
value=14; fillcolor='blue'; output;
value=15; fillcolor='black'; output;
value=16; fillcolor='cyan'; output;
run;


proc summary data=sashelp.class nway;
class age;
var weight;
output out=class mean=;
run;

proc sgplot data=class dattrmap=myattrs;
vbarparm category=age response=weight / group=age seglabel dataskin=matte attrid=jrc_ID datalabel;
run;

 

 

What I would like to do is set the color of the font inside the each bar to a different color, for example blue bar = yellow font, green bar = white font, cyan bar = black font, etc.

 

I tried seglabelattrs but it will only take one color for the font.

 

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

This may not be the best way but it works. Basically calculate a Y position for a TEXT plot and don't use the seglabel or datalabel options.

 

data work.myattrs;
length value fillcolor $12;
show='AttrMap';
id="jrc_ID";
value=11; fillcolor='red';textcolor='yellow'; output;
value=12; fillcolor='yellow';textcolor='red'; output;
value=13; fillcolor='green';textcolor='purple'; output;
value=14; fillcolor='blue';textcolor='orange'; output;
value=15; fillcolor='black';textcolor='white'; output;
value=16; fillcolor='cyan';textcolor='black'; output;
run;


proc summary data=sashelp.class nway;
class age;
var weight;
output out=class mean=;
run;
data class;
   set class;
   y= weight/2;
   text = put(weight,best4.);
run;

proc sgplot data=class dattrmap=work.myattrs;
vbarparm category=age response=weight / group=age  dataskin=matte attrid=jrc_ID ;
text x=age y=y text=text/ attrid=jrc_ID group=age;
run;

Calculating a segment label location for stacked elements may be tad trickier but the general approach works. I'm not sure if a later version has more options for segment text in either the dattrmap set or options. 

View solution in original post

2 REPLIES 2
ballardw
Super User

This may not be the best way but it works. Basically calculate a Y position for a TEXT plot and don't use the seglabel or datalabel options.

 

data work.myattrs;
length value fillcolor $12;
show='AttrMap';
id="jrc_ID";
value=11; fillcolor='red';textcolor='yellow'; output;
value=12; fillcolor='yellow';textcolor='red'; output;
value=13; fillcolor='green';textcolor='purple'; output;
value=14; fillcolor='blue';textcolor='orange'; output;
value=15; fillcolor='black';textcolor='white'; output;
value=16; fillcolor='cyan';textcolor='black'; output;
run;


proc summary data=sashelp.class nway;
class age;
var weight;
output out=class mean=;
run;
data class;
   set class;
   y= weight/2;
   text = put(weight,best4.);
run;

proc sgplot data=class dattrmap=work.myattrs;
vbarparm category=age response=weight / group=age  dataskin=matte attrid=jrc_ID ;
text x=age y=y text=text/ attrid=jrc_ID group=age;
run;

Calculating a segment label location for stacked elements may be tad trickier but the general approach works. I'm not sure if a later version has more options for segment text in either the dattrmap set or options. 

cuevasj
Quartz | Level 8

This is doing exactly what I need it to do.

Thank you.

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