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.

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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