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?
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.
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;
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...
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
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
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Ready to level-up your skills? Choose your own adventure.