BookmarkSubscribeRSS Feed
AnneHsr
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);
run;

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.

1 REPLY 1
ballardw
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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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