BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kedarnath_M
Obsidian | Level 7

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.

Screen Shot 2021-09-14 at 9.42.28 AM.pngor  Screen Shot 2021-09-14 at 11.22.20 AM.png

 

Screen Shot 2021-09-14 at 11.30.05 AM.png

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 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

Ksharp_0-1631715317451.png

 

View solution in original post

8 REPLIES 8
Reeza
Super User

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? 

 

 

 

Kedarnath_M
Obsidian | Level 7

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;

Screen Shot 2021-09-14 at 1.04.02 PM.png

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. 

Reeza
Super User
So your question isn't how to add it to graph, its how to identify which records are statistically significant?
https://communities.sas.com/t5/Statistical-Procedures/Comparing-means-between-several-groups/td-p/34...

Kedarnath_M
Obsidian | Level 7

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;

Screen Shot 2021-09-14 at 1.42.00 PM.png

And these are all the significant differences between the groups

 

Reeza
Super User
1. You've shown three graphs. Are you trying to create all three or a specific one? It seems like you have two of the three coded? We cannot run the code you've posted so no idea where you are on that.
2. It looks like you have the pairs comparison to identify the difference, but don't know how to merge that in to your data to present it graphically?

Instead of using the narwhal data set perhaps consider using sashelp.HEART or CARS so someone can help you out with public data if you cannot share your private data.
Kedarnath_M
Obsidian | Level 7

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.

Screen Shot 2021-09-12 at 4.08.09 PM.png

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.

Ksharp
Super User
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;

Ksharp_0-1631715317451.png

 

Kedarnath_M
Obsidian | Level 7

This sir, is straight genius.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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