Sample 24871: Add bars at +/- 1, 2 or 3 STD or STDERR of the MEAN
/**************************************************************************************/
/* This program uses the ANNOTATE facilty to overlay bars at +/- 1, 2 or 3 STD */
/* (Standard deviation/s) or STDERR (Standard Error/s) of the MEAN on an HBAR chart. */
/* The MIN and MAX values for each midpoint are also shown. */
/**************************************************************************************/
/* Set graphics options */
goptions reset=all cback=white border;
/* Set system options */
options symbolgen mlogic mprint;
%let stat=std; /* At this point your choices are either std or stderr */
%let num=1; /* Choose either, 1, 2, or 3 for the number of std or */
/* stderr of the mean */
/* Create input data set, A */
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 60
Xrays 20
Xrays 25
Xrays 14
Xrays 22
Xrays 29
Humidity 20
Humidity 25
Humidity 33
Humidity 40
Humidity 24
;
/* Sort data by variable TEST */
proc sort;
by TEST;
run;
/* Create an output data set, B using PROC MEANS */
/* that contain new variables, MEAN, STD, STDERR, */
/* MIN, and MAX. */
proc means mean std stderr min max data=a;
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 Deviation or Standard Error 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; x=mean; color='blue'; output;
function='draw'; x=mean-(&num*&stat); color='blue'; width=2; output;
function='draw'; x=mean+(&num*&stat); color='blue'; width=2; output;
function='move'; midpoint=TEST; x=mean; color='red'; output;
function='draw'; x=mean; ysys='9'; y=+2; width=2; output;
function='draw'; x=mean; y=-4; width=2; output;
function='move'; x=mean-(&num*&stat); ysys='2'; midpoint=TEST;
color='blue'; width=2; output;
function='draw'; ysys='9'; y=+1; width=2; output;
function='draw'; y=-2; width=2; output;
function='move'; x=mean+(&num*&stat); ysys='2'; midpoint=TEST;
color='blue'; width=2; output;
function='draw'; ysys='9'; y=+1; width=2; color='blue'; output;
function='draw'; y=-2; width=2; color='blue'; output;
function='label'; xsys='2'; ysys='2'; x=min; style='marker';
size=.75; text='V'; color='red'; output;
function='label'; xsys='2'; ysys='2'; x=max; style='marker';
size=.75; text='V'; color='red'; output;
run;
/* Create an annotate data set, ANNO2 that draws the legend for the graph. */
data anno2;
length function style $8. text $45;
retain xsys '2' ysys '1' when 'a' line 2 function 'label' hsys '3' size .5;
/*do i=10 to 90 by 10;
function='move'; x=i; y=0; color='black'; size=.5; output;
function='draw'; x=i; y=100; color='black'; size=.5; output;
end;
*/
function='move'; xsys='3'; ysys='3'; x=20; y=8; line=1; color='black'; output;
function='draw'; x=20; y=12; output;
function='draw'; x=90; y=12; output;
function='draw'; x=90; y=8; output;
function='draw'; x=20; y=8; output;
function='move'; xsys='3'; ysys='3'; x=22; y=10; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='9'; x=22; y=+1; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='9'; x=22; y=-2; line=1; color='blue'; output;
function='move'; xsys='3'; ysys='3'; x=25; y=10; line=1; color='red'; output;
function='draw'; xsys='3'; ysys='9'; x=25; y=+1; line=1; color='red'; output;
function='draw'; xsys='3'; ysys='9'; x=25; y=-2; line=1; color='red'; output;
function='move'; xsys='3'; ysys='3'; x=28; y=10; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='9'; x=28; y=+1; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='9'; x=28; y=-2; line=1; color='blue'; output;
function='move'; xsys='3'; ysys='3'; x=22; y=10; line=1; color='blue'; output;
function='draw'; xsys='3'; ysys='3'; x=28; y=10; line=1; color='blue'; output;
function='label'; xsys='3'; ysys='3'; x=30; y=10.5;
style='swiss'; position='6';size=2.25;
if "&stat"='std' then text=("Plus/Minus &num Standard Deviation");
if "&stat"='stderr' then text=("Plus/Minus &num Standard Error of the Mean");
color='black'; output;
function='label'; xsys='9'; x=+2; y=10.1; style='marker';
size=1.5; text='V'; color='red'; output;
function='label'; xsys='9'; x=+1; y=10.5; style='swiss';
size=2; text='Min and Max'; color='black'; output;
run;
proc print data=anno2;
run;
/* Define patterns for the bars. */
pattern1 v=e c=blue r=3;
/* Create axis definitions */
axis1 order=(0 to 75 by 25) length=70 pct origin=(20.5,30)
pct value=(f=swiss) label=(f=swiss);
axis2 value=(f=swiss) label=(f=swiss);
/* Add the titles */
title1 h=7 pct ' ';
title2 h=5 pct f=swissb 'Test Results';
/* Produce the chart */
proc gchart data=b anno=anno2;
hbar TEST / raxis=axis1 nostats anno=anno frame maxis=axis2 sumvar=mean;
run;
quit;

This program uses the ANNOTATE facilty to overlay bars at +/- 1, 2 or 3 STD (Standard deviation/s) or STDERR (Standard Error/s) of the MEAN on an HBAR chart. The MIN and MAX values for each midpoimt are also shown.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GCHART Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Statistical Graph Enhancements
|
| Date Modified: | 2008-01-18 15:10:20 |
| Date Created: | 2004-11-11 11:07:53 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |