You can use the ERRORBAR option in the VBAR or HBAR statement of PROC GCHART to display error bars for your statistics. However, you can also use the Annotate facility to create standard error bars on a vertical bar chart. The sample code on the Full Code tab demonstrates the annotate method.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* Set the graphics environment */
goptions reset=all border cback=white htitle=12pt htext=10pt;
%let stat=std; /* Choose either STD or STDERR. */
%let num=1; /* Choose either, 1, 2, or 3 for the number of standard */
/* deviations or standard errors of the mean. */
/* Create a sample data set */
data a;
input Test $8. breaks;
datalines;
Cold 5
Cold 12
Cold 14
Cold 22
Cold 52
Heat 20
Heat 25
Heat 10
Heat 22
Heat 47
Gases 12
Gases 25
Gases 33
Gases 48
Gases 24
Pressure 10
Pressure 12
Pressure 14
Pressure 22
Pressure 55
X-rays 20
X-rays 25
X-rays 14
X-rays 22
X-rays 29
Humidity 20
Humidity 25
Humidity 33
Humidity 40
Humidity 24
;
run;
/* Sort data by variable Test */
proc sort data=a;
by test;
run;
/* Create an output data set B using PROC MEANS */
/* that contains new variables MEAN, STD, STDERR, */
/* MIN, and MAX. */
proc means mean std stderr min max data=a noprint;
by test;
output out=b mean=mean std=std stderr=stderr min=min max=max;
run;
/* Create an annotate data set, ANNO, to draw the bars at +/- 1, */
/* 2, or 3 standard deviations or standard errors of the mean. */
data anno;
length color function style $8;
retain xsys ysys '2' when 'a' ;
set b;
function='move'; xsys='2'; ysys='2'; midpoint=test; y=mean; color='blue'; output;
function='draw'; y=mean-(&num*&stat); color='blue'; width=2; output;
function='draw'; y=mean+(&num*&stat); color='blue'; width=2; output;
function='move'; y=mean-(&num*&stat); xsys='2'; midpoint=test;
color='blue'; width=2; output;
function='draw'; xsys='9'; x=+1; width=2; output;
function='draw'; x=-2; width=2; output;
function='move'; y=mean+(&num*&stat); xsys='2'; midpoint=test;
color='blue'; width=2; output;
function='draw'; xsys='9'; x=+1; width=2; color='blue'; output;
function='draw'; x=-2; width=2; color='blue'; output;
/* Draw a symbol at the minimum and maximum values */
function='label'; xsys='2'; ysys='2'; y=min; style='marker';
size=1; text='C'; color='depk'; output;
function='label'; xsys='2'; ysys='2'; y=max; style='marker';
size=1; text='C'; color='depk'; output;
run;
/* Create an annotate data set, ANNO2, that draws the legend for the graph. */
data anno2;
length function $ 8 text style $ 45;
retain xsys '2' ysys '1' when 'a' line 2 function 'label' hsys '3' size 0.5;
function='move'; xsys='3'; ysys='3'; x=25; y=6; output;
function='bar'; x=75; y=10; style='empty'; color='black'; line=0; output;
function='move'; xsys='3'; ysys='3'; x=27; y=8; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='9'; x=27; y=+1; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='9'; x=27; y=-2; line=1; color='blue'; output;
function='move'; xsys='3'; ysys='3'; x=33; y=8; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='9'; x=33; y=+1; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='9'; x=33; y=-2; line=1; color='blue'; output;
function='move'; xsys='3'; ysys='3'; x=27; y=8; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='3'; x=33; y=8; line=1; color='blue'; output;
function='label'; xsys='3'; ysys='3'; x=35; y=8.5;
style="'Albany AMT'"; position='6'; size=2.5;
if "&stat"='std' then text=("+/- &num Standard Deviation");
if "&stat"='stderr' then text=("+/- &num Standard Error of the Mean");
color='black'; output;
function='label'; xsys='9'; x=+2; y=8.1; style='marker';
size=2; text='C'; color='depk'; output;
function='label'; xsys='9'; x=+1; y=8.5; style="'Albany AMT'";
size=2.5; text='Min and Max'; color='black'; output;
run;
/* Create axis definitions */
axis1 order=(0 to 60 by 10) label=(angle=90 "Mean")
length=65 pct origin=(10,25) pct;
/* Add a title to the graph */
title1 'Annotate Standard Error Bars';
/* Create the graph using the ANNOTATE= */
/* option in the PROC GCHART statement */
/* and in the VBAR statement. */
proc gchart data=b annotate=anno2;
vbar test / raxis=axis1 annotate=anno
frame sumvar=mean;
run;
quit;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> GCHART Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Annotation Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Charts ==> Bar |
Date Modified: | 2012-10-03 14:03:56 |
Date Created: | 2012-07-27 08:25:56 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/GRAPH | Linux for x64 | 9.3 TS1M0 | |
Linux | 9.3 TS1M0 | |||
HP-UX IPF | 9.3 TS1M0 | |||
64-bit Enabled Solaris | 9.3 TS1M0 | |||
64-bit Enabled HP-UX | 9.3 TS1M0 | |||
64-bit Enabled AIX | 9.3 TS1M0 | |||
Windows Vista for x64 | 9.3 TS1M0 | |||
Windows Vista | 9.3 TS1M0 | |||
Windows 7 Ultimate x64 | 9.3 TS1M0 | |||
Windows 7 Ultimate 32 bit | 9.3 TS1M0 | |||
Windows 7 Professional x64 | 9.3 TS1M0 | |||
Windows 7 Professional 32 bit | 9.3 TS1M0 | |||
Windows 7 Home Premium x64 | 9.3 TS1M0 | |||
Windows 7 Home Premium 32 bit | 9.3 TS1M0 | |||
Windows 7 Enterprise x64 | 9.3 TS1M0 | |||
Windows 7 Enterprise 32 bit | 9.3 TS1M0 | |||
Microsoft Windows XP Professional | 9.3 TS1M0 | |||
Microsoft Windows Server 2008 for x64 | 9.3 TS1M0 | |||
Microsoft Windows Server 2008 R2 | 9.3 TS1M0 | |||
Microsoft Windows Server 2008 | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 for x64 | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.3 TS1M0 | |||
Microsoft® Windows® for x64 | 9.3 TS1M0 | |||
z/OS | 9.3 TS1M0 | |||
Solaris for x64 | 9.3 TS1M0 |