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.
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.
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.
This is doing exactly what I need it to do.
Thank you.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.