BookmarkSubscribeRSS Feed
Calcite | Level 5
ods html style = journal2;
proc sgplot data =WORK.PLAY pctlevel=group;
hbar Q68 / GROUP=Q3 groupdisplay=stack grouporder=descending 
stat=percent barwidth=0.80 seglabel seglabelattrs=(family="Arial" size=12pt weight=bold) seglabelfitpolicy=noclip datalabel=; keylegend/ noborder title="" location=outside position=right across=1 valueattrs=(size=13pt) sortorder=descending;
yaxis valueattrs=(Family="Arial" size= 13pt) label = "Sex" Labelattrs=(family="Arial" size= 13pt);
xaxis valueattrs=(Family="Arial" size= 13pt) label = "Percentage" Labelattrs=(Family= "Arial" size= 13pt);

Hello there,


I am stuck and need to have a readable graph.  I am creating a bivariate horizontal bargraph (of Q3No. of ER visits vs. Q68sex) using PROC SGPLOT with Journal2 style. Is there any way I can move the segment labels from inside the bars to outside just so that they are legible? Apologies, I am unable to show the data.


The output for the code below is shown in attachment "figure ER visits vs sex".


I am looking to produce the graph with labels as seen in the attachment "What I want my graph to look like ER vs sex".


I appreciate the help.

Super User

The basic approach I would take would be to

1) summarize the data creating the percentage values you need

2) add the TEXT of the values as a new variable with compatible horizontal and vertical axis values

3) add a TEXT plot

4) modify the hbar to remove segment labels entirely and make sure there is sufficient space between the bars for the text and to have a TEXT plot an HBARPARM would be needed for compatibility.


If your current variable for Sex is character you may need to change to a numeric with appropriate format so the X Y coordinates can make sense.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1 like
  • 2 in conversation