SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mcknigh3
Fluorite | Level 6

Hi there, 

I am having trouble adding error bars to each bar in my vertical bar chart using Proc sgplot. First of all, is this even possible? Every discussion forum/questions never shows grouped bar charts. I have all the options on in my code to enable error bars but they are not being produced on the graph. My code is below - Is there a step I am missing?

Proc sgplot data=LSMTrtTOD1;
vbar TOD / response=Estimate stat=mean numstd=2 limitstat=stderr limits=both
group=Trt groupdisplay=cluster fillpattern nofill;
keylegend / position=top noborder;
yaxis grid;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Ah...you're trying to reference a variable STDERR and this plot is calculating it dynamically which you are not doing.
I think you want to use VBARPARM instead where you specify the pre-calculated statistics.

View solution in original post

11 REPLIES 11
ballardw
Super User

Data?

Can't test code without data.

mcknigh3
Fluorite | Level 6

Sorry I was having trouble adding data - it's attached as a file.

 

Reeza
Super User

Works fine for me - perhaps your errors are quite small? Note that not all bars have error bars, haven't investigated why but guessing it has to do with the N involved or to small to see. 

 

Proc sgplot data=LSMTrtTOD1;
vbar TOD / response=Estimate stat=mean numstd=2 limitstat=stderr limits=both
group=Trt groupdisplay=cluster fillpattern nofill;
keylegend / position=top noborder;
yaxis grid;
Run;

 


@mcknigh3 wrote:

Hi there, 

I am having trouble adding error bars to each bar in my vertical bar chart using Proc sgplot. First of all, is this even possible? Every discussion forum/questions never shows grouped bar charts. I have all the options on in my code to enable error bars but they are not being produced on the graph. My code is below - Is there a step I am missing?

Proc sgplot data=LSMTrtTOD1;
vbar TOD / response=Estimate stat=mean numstd=2 limitstat=stderr limits=both
group=Trt groupdisplay=cluster fillpattern nofill;
keylegend / position=top noborder;
yaxis grid;
Run;

 

mcknigh3
Fluorite | Level 6

You can see them on the graph though? Because I can't. 

Reeza
Super User
If you run the exact code I posted - no changes do you see error bars?
I changed the code to reference the sashelp.cars data set and it works for me.
Reeza
Super User
Ah...you're trying to reference a variable STDERR and this plot is calculating it dynamically which you are not doing.
I think you want to use VBARPARM instead where you specify the pre-calculated statistics.
mcknigh3
Fluorite | Level 6

Thank you - this worked! Would there be a reason why the upper limit bar isn't being displayed though?

Reeza
Super User
Can you share your new code?
mcknigh3
Fluorite | Level 6
Proc sgplot data=LSMTrtTOD1 noborder;
vbarparm category=TOD response=Estimate / limitlower=stderr limitupper=stderr
group=Trt groupdisplay=cluster fillpattern nofill ;
yaxis grid Label= 'Daily distance (m)';
Run;

Sorry - I am pretty well new at this! 

Reeza
Super User
Limit lower and upper require the actual values (ie Estimate+stderr = upper), so you need to do the math prior to this step to provide the actual values, not just the error value.
mcknigh3
Fluorite | Level 6

Ah yes - thank you so much!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 4838 views
  • 2 likes
  • 3 in conversation