Hi,
I'm trying to add a star (*) on top of the bars that are significantly different (between the 2 endpoints) in a bar chart. Please see the code below. I've tried using DATALABEL, but SAS won't allow the labels for different bars to be the same. And I can't figure out how to use an annotated dataset here correctly. I'm using SAS version 9.3.
In my dataset I have 2 different endpoints (type) and 5 treatment groups (group).
PROC SGPLOT DATA=work10;
VBARPARM CATEGORY=group RESPONSE=gm/ GROUP=type LIMITUPPER=Upper2;
XAXIS DISCRETEORDER=DATA;
YAXIS LABEL="Geometric mean (AU/mL)";
KEYLEGEND / TITLE="Groups";
RUN;
Is there any way to do this?
Since you are using VBARPARM, you should be able to overlay a scatter plot with y=upper2 to plot markers where you want them.
The key here is the LIMITUPPER request. Data labels over the bars are not allowed when LIMITUPPER/LIMITLOWER are used. Without that option, the DATALABEL option works as expected, as demonstrated by the following program:
proc summary data=sashelp.class nway;
class age sex;
var weight;
output out=temp mean= uclm=uclm;
run;
data dlabel;
set temp;
if (sex eq 'M') then dlabel="*";
else dlabel=" ";
run;
proc sgplot data=dlabel;
vbarparm category=age response=weight / group=sex datalabel=dlabel groupdisplay=cluster;
run;
Fortunately, you can use annotation to get around this issue. But, my question to you is, "Do you want the star on top of the bar, or at the end of the limit bar?".
Thank you Dan, that explains why the datalabel option doesn't work. I would prefer the star to be at the end of the limit bar.
Since you are using VBARPARM, you should be able to overlay a scatter plot with y=upper2 to plot markers where you want them.
Ah, thank you Sanjay. That seems to be doing the trick!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.