I looked at another topic that discusses this but I'm still very lost.
With the code at the bottom I understand how to put a star above a bar but I only want to put that star there if there is a significant difference in the means. So I'm a bit lost on how to tie all of that in together.
I also ran a proc anova with a post hoc test (tukey) on my data so I know which bars are significant comparing them together.
It'd be nice if there was a way to do it through the proc sgplot procedure itself.
I'm try to get it to look like the images below.
or
This is the original code for the graph above
ods graphics on / width=15in height=6in noborder ;
ods listing style =styles.mine;
title '[P]in X';
proc sgplot data=Narwhal.Narwhal_Data (where=(Location Contains 'X'));
vbar Dependant_V / response=N_Concentration group=Experiment_Group groupdisplay=cluster
stat=mean limitstat=stderr alpha=.05 ;
xaxis /*display=(nolabel noticks)*/ label="Package"
values=('X_A' 'X_C' 'X_D' 'X_E' 'X_B' 'X_F');
yaxis grid label="Concentration (pines/apples)";
run;
And this is the code I made following the other topic
Proc summary data=narwhal.narwhal_data nway;
Class Experiment_group Package;
var N_Concentration;
output out=tempp mean=uclm=uclm ;
run;
data dlabel;
set tempp;
if (uclm>30) then dlabel="*";
else dlabel="";
run;
proc sgplot data=dlabel;
vbarparm category=package response=N_Concentration / group=Experiment_Group datalabel=dlabel groupdisplay=cluster;
run;
I'm using SAS OnDemand for academics
proc summary data=sashelp.heart nway;
class status Weight_Status;
var Systolic;
output out=have mean=mean std=std lclm=lclm uclm=uclm;
run;
data have ;
set have;
if Weight_Status in ('Overweight' 'Underweight') and status='Dead' then star=mean+std;
run;
proc sgplot data=have;
symbolchar name=uniStar char='2605'x;
vbarparm category=status response=mean/ group=Weight_Status groupdisplay=cluster LIMITLOWER=lclm LIMITUPPER=uclm ;
scatter x=status y=star /markerattrs=(symbol=unistar size=36pt) group=Weight_Status groupdisplay=cluster ;
run;
There isn't a way to do it in SGPLOT directly you would need to pre-process your data to identify when you wanted to add that extra label.
If you add the asterisk in you can assign a variable as your datalabel in SGPLOT, which I see you've done below. Did that not work for you?
No the problem was with that code it included a significance star on the graph if the mean was greater than 30, but I only want it to include a star if the difference between the means is a significant amount, like if the error bars don't over lap.
data dlabel;
set tempp;
if (uclm>30) then dlabel="*";
else dlabel="";
run;
like these were the results of the post hoc test from the anova I ran and I want only these groups to have an asterisk.
I guess another way of putting it for this data set is if the difference between the means is greater then 22 (not If the mean is above 22) then SAS should include a star on top of the bar that is higher.
I already identified which groups are significant using the anova and the post hoc test but I just don't know how to translate that over to the proc sgplot.
Thats my anova code down below so I got the results for that
ods graphics on;
proc anova data = hedgehog.DATA;
class Experiment_Group;
model a b c d e f=Experiment_Group;
means Experiment_Group/hovtest=bf clm cldiff t tukey
alpha=.05;
ods output cldiffs=diffs;
run;
ods graphics off;
And these are all the significant differences between the groups
1. I'm trying to get this graph to have the asterisks, the other 2 graphs (the pictures) aren't mine they were just examples of how I wanted the graph to look like.
2. yup that's the problem
Good idea! I'll try to use one of the sashelp data steps to represent it it might take awhile to do that though.
proc summary data=sashelp.heart nway;
class status Weight_Status;
var Systolic;
output out=have mean=mean std=std lclm=lclm uclm=uclm;
run;
data have ;
set have;
if Weight_Status in ('Overweight' 'Underweight') and status='Dead' then star=mean+std;
run;
proc sgplot data=have;
symbolchar name=uniStar char='2605'x;
vbarparm category=status response=mean/ group=Weight_Status groupdisplay=cluster LIMITLOWER=lclm LIMITUPPER=uclm ;
scatter x=status y=star /markerattrs=(symbol=unistar size=36pt) group=Weight_Status groupdisplay=cluster ;
run;
This sir, is straight genius.
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.