BookmarkSubscribeRSS Feed
Recep
Quartz | Level 8

Hello all,

The following program creates the data labels separate from the graph and places them on the right hand-side. is there any option to put the data labels right on top of each bar (and the ends of each bar for the confidence limits)?

Thanks a lot in advance!

Recep

 

proc sgplot data=rr_blunt_penetrating_01;
hbarparm category=Site response=Log_RR/ limitlower=Log_LCL
limitupper=Log_UCL
datalabel;
run;

 

 

4 REPLIES 4
ghosh
Barite | Level 11

add another option to hbarparam, eg

DATALABELPOS=DATA

 

If it does not work please provide sample data

 

Recep
Quartz | Level 8

Sorry for the late response, just got back from a quick break!

I already tried the DATALABELPOS=data option but it did not work for me. It simply places the labels on the right hand-side of the figure:

 

Below is the sample data and the SGPLOT code.

 

Thanks a lot again!

 

Recep

 

data relative_risks;
input hospital $ RR LCL UCL;
cards;
Hosp1 1.00424 0.82114 1.22818
Hosp2 0.8101 0.6657 0.98582
Hosp3 0.90292 0.68763 1.1856
Hosp4 1.06134 0.82583 1.36402
Hosp5 0.79188 0.56884 1.10237
Hosp6 0.85667 0.74326 0.98739
Pooled 0.89249 0.81989 0.97151
run;

ods graphics on;
ods html style=statistical;
proc sgplot data=relative_risks;
hbarparm category=hospital response=RR/ limitlower=LCL
limitupper=UCL
datalabel
datalabelpos=DATA;
run;
ods graphics off;
ods html close;

 

 

DanH_sas
SAS Super FREQ

Given your use case, you could drop the DATALABEL option and overlay a TEXT plot on top of the HBARPARM. Use the same variables you used for the HBARPARM to place the text values. Use the POSITION option on the TEXt statement to adjust the text position around the data points.

 

Hope this helps!

Dan

Recep
Quartz | Level 8

Thanks a lot for this Dan! I'll definitely try it. I was hoping to find a straight option but it seems like there is no one within the SGPLOT.

 

Recep

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 3618 views
  • 0 likes
  • 3 in conversation