BookmarkSubscribeRSS Feed
xxformat_com
Barite | Level 11

In the presented Grotta barcharts, the same text color is applied to all segments.

Is it possible to apply different text colors to different segments (eg. white for dark backgrounds and black for other backgrounds) with proc sgplot simply or must proc template/sgrender be used?

 

With proc sgplot, I only see the text statement (but needs lots of data preparation for it) and annotations as possible solution. Correct?

 

  • seglabelattrs(color=) does not allow multiple colors
  • textcolor from a dattrmap table is not working with datalabel/seglabel
  • styleattrs statement: does not offer this feature.
  • proc template: class GraphDataText apply the same color to all segements
  • axistable would not be usable to add values in that case

 

 

 

 

1 REPLY 1
Ksharp
Super User

It does not look like so hard I think .Just prepare the data and using TEXT statement.

 

proc freq data=sashelp.heart noprint;
table status*bp_status/out=temp outpct;
run;
data want;
 set temp;
 by status;
 if first.status then cum_pct=0;
 pct=PCT_ROW*0.01;
 cum_pct+pct;
 x=cum_pct-pct/2;
 format cum_pct pct x percent8.2;
run;
proc sgplot data=want;
styleattrs datacontrastcolors=(black white navy);
hbarparm category=status response=pct/group=bp_status nooutline;
text x=x y=status text=pct/strip contributeoffset=none group=bp_status textattrs=(size=14);
run;

Ksharp_0-1721092120018.png

 

sas-innovate-white.png

Missed SAS Innovate in Orlando?

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.

 

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
  • 1 reply
  • 575 views
  • 1 like
  • 2 in conversation