BookmarkSubscribeRSS Feed
josuerodrigues
Calcite | Level 5

Hello. I'm plotting soil pH vs sources of nutrients. Until now I do a plot in PROC SGPLOT, but I don't know how can I put the standard error of the mean in the vbar. The first graph is my code and the second is the model that I'm trying to do. Furthermore, how can I insert the letters beside the values as we see in the second graph? 

josuerodrigues_0-1722168547873.gif 

josuerodrigues_1-1722168609673.png

 

 

7 REPLIES 7
ballardw
Super User

Your current code helps. Then we can discuss variables by name as needed. For vertical and horizontal bar plots this is a bit more important because there are three plots available: Vbar, Vbarbasic and Vbarparm (and Hbar equivalents). Which have somewhat different approaches.

 

Best would be to include example data in the form of a working data step to test code with.

 

By "insert standard error" do you mean add an error bar or use the standard error as a label for the bar? Depending on which Vbar statement and which statistic is requested for the bar (see, the code is important) the option LIMITS= is used to create the error bars and the LIMITSTAT=STDERR is used for which statistic is used for the limit to display (or confidence limit of the mean or standard deviation). If you are not using a STAT=MEAN then error bars won't be calculated by the procedure and you need to add such to the data before the plot so you can use other options and other plot statements.

 

Display of any text requires a value and format. Do you have a variable holding the text you want?

The DATALABEL= option will take the name of a variable holding the desired values if other that the default calculated value of the bar height. Which is yet another reason to share data and your code.

josuerodrigues
Calcite | Level 5

Thanks for answer me. For "insert standard error" I wanna mean an error bar. I want also to add letters above each bar, such as "a, b, c, d and e". My current code is below:

 

data teste;
input trat$ rep pHsolo;
cards;
Controle 1 7.51
Controle 2 7.1
Controle 3 7.71
Controle 4 7.6
Controle 5 7.44
0 1 7.69
0 2 6.76
0 3 6.54
0 4 7.3
0 5 7.64
100 1 7.57
100 2 7.13
100 3 7.6
100 4 7.56
100 5 7.87
200 1 7.56
200 2 7.67
200 3 7.73
200 4 7.58
200 5 7.55
300 1 7.67
300 2 7.41
300 3 7.77
300 4 7.58
300 5 7.81
;
title "pH do solo em função de fontes de adubos";
proc sgplot data=composto2 noautolegend noborder;
vbar trat / response=Nsolo datalabel datalabelattrs=(color=black size=10 family=arial) fillattrs=(color=VIGB) outlineattrs=(color="black") ;
yaxis label="pH do solo" LABELATTRS=(Color=black Family=Arial Size=12) valueattrs=(Color=black Family=Arial Size=10);
xaxis label="Fonte de adubo" LABELATTRS=(Color=black Family=Arial Size=12) valueattrs=(Color=black Family=Arial Size=10);
run;

josuerodrigues
Calcite | Level 5
I change my PROC SGPLOT code with:title "pH do solo em função de fontes de adubos";
proc sgplot data=composto2 noautolegend noborder;
vbar trat / response=Nsolo stat=mean limitstat=stderr limitattrs=(color=black) fillattrs=(color=VIGB) outlineattrs=(color="black") datalabel datalabelattrs=(color=black size=10 family="Times New Roman") fillattrs=(color=VIGB) outlineattrs=(color="black") ;
yaxis label="pH do solo" LABELATTRS=(Color=black Family="Times New Roman" Size=12) valueattrs=(Color=black Family="Times New Roman" Size=10);
xaxis label="Fonte de adubo" LABELATTRS=(Color=black Family="Times New Roman" Size=12) valueattrs=(Color=black Family="Times New Roman" Size=10);
run;

Now I can put stderr bar, but I couldn't put the letters to mark significant differences. Please help me.
Quentin
Super User

Hi,

Please post a small example dataset as a DATA step with the CARDS statement, and also post the code you have to make your current graph.  That will help people help you, because you'll be giving them the data to work with, and your actual code. 

If you google "SAS SGLOT VBAR error bar" you'll find hits to few similar questions here on SAS communities, e.g.:
https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-Create-Error-Bars-in-Stacked-VBar-Gr...

https://communities.sas.com/t5/SAS-Programming/How-to-add-error-bars-to-a-clustered-vertical-bar-gra...


If you google "site:blogs.sas.com vbar error" you'll get great blog posts like:

https://blogs.sas.com/content/graphicallyspeaking/2016/11/27/getting-started-sgplot-part-2-vbar/

https://blogs.sas.com/content/iml/2011/10/07/creating-bar-charts-with-confidence-intervals.html

 

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
sbxkoenk
SAS Super FREQ

There is also the 
Graphics Samples Output Gallery
(Learn how to build interesting graphics)
https://support.sas.com/en/knowledge-base/graph-samples-gallery.html

 

BR, Koen

Ksharp
Super User
proc summary data=sashelp.heart(obs=100) nway;
class bp_status;
var weight;
output out=have mean=mean lclm=lclm uclm=uclm;
run;
data have;
 set have;
 label=choosec(_n_,'a','abc','a');
run;

proc sgplot data=have noautolegend;
vbarparm category=bp_status response=mean;
highlow x=bp_status low=lclm high=uclm/lowcap=serif highcap=serif highlabel=label labelattrs=(size=12);
run;

Ksharp_0-1722216105815.png

 

svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
+1 for commandeering HIGHLOW to display standard error bars

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!

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 836 views
  • 3 likes
  • 6 in conversation