You can use a procedure such as PROC MEANS to calculate the means and standard errors. You can then use these values to calculate the upper and lower error bar limits in a DATA step. Use the HILOCTJ interpolation with PROC GPLOT to generate the graph.
When plotting groups of data with the GPLOT procedure, you can offset the group values from one another by adding or subtracting a small value from the X-axis variable. The sample code on the Full Code tab illustrates this.
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.
You can use a procedure such as PROC MEANS to calculate the means and standard errors. You can then use these values to calculate the upper and lower error bar limits in a DATA step. Use the HILOCTJ interpolation with PROC GPLOT to generate the graph.
When plotting groups of data with the GPLOT procedure, you can offset the group values from one another by adding or subtracting a small value from the X-axis variable. The sample code below illustrates this.
/* Set the graphics environment */
goptions reset=all cback=white border htext=10pt htitle=12pt;
/* Create sample data */
data test(drop=i);
do groupvar='A','B';
do i=1 to 10;
do xvar=1 to 5;
yvar=ranuni(0)*100;
output;
end;
end;
end;
run;
proc sort data=test;
by groupvar xvar;
run;
/* Calculate the mean and standard error for each X */
proc means data=test noprint;
by groupvar xvar;
var yvar;
output out=meansout(drop=_type_ _freq_) mean=mean stderr=stderr;
run;
/* Reshape the data to contain three Y values for */
/* each X for use with the HILOC interpolation. */
data reshape(keep=groupvar xvar yvar mean);
set meansout;
by groupvar xvar;
/* Offset the X values to display two groups */
if groupvar='A' then xvar=xvar - 0.08;
else if groupvar='B' then xvar=xvar + 0.08;
yvar=mean;
output;
yvar=mean - stderr;
output;
yvar=mean + stderr;
output;
run;
/* Define the title */
title1 'Plot Means with Standard Error Bars from Calculated Data for Groups';
/* Define the axis characteristics */
axis1 offset=(0,0) minor=none value=(t=1 ' ' t=7 ' ');
axis2 label=(angle=90) order=(20 to 80 by 10) minor=(n=1);
/* Define the symbol characteristics */
symbol1 interpol=hiloctj color=vibg line=1;
symbol2 interpol=hiloctj color=depk line=2;
symbol3 interpol=none color=vibg value=dot height=1.5;
symbol4 interpol=none color=depk value=dot height=1.5;
/* Define the legend characteristics */
legend1 label=('Group:') frame;
/* Plot the error bars using the HILOCTJ interpolation */
/* and overlay symbols at the means. */
proc gplot data=reshape;
plot yvar*xvar=groupvar / haxis=axis1 vaxis=axis2 legend=legend1;
plot2 mean*xvar=groupvar / vaxis=axis2 noaxis nolegend;
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 ==> GPLOT Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Symbols/Interpolation Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Plots ==> Other Plots |
Date Modified: | 2013-06-18 13:10:15 |
Date Created: | 2013-06-18 12:42:20 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/GRAPH | z/OS | 9.2 TS1M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |||
Microsoft® Windows® for x64 | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |||
Microsoft Windows XP Professional | 9.2 TS1M0 | |||
Windows Vista | 9.2 TS1M0 | |||
Windows Vista for x64 | 9.2 TS1M0 | |||
64-bit Enabled AIX | 9.2 TS1M0 | |||
64-bit Enabled HP-UX | 9.2 TS1M0 | |||
64-bit Enabled Solaris | 9.2 TS1M0 | |||
HP-UX IPF | 9.2 TS1M0 | |||
Linux | 9.2 TS1M0 | |||
Linux for x64 | 9.2 TS1M0 | |||
OpenVMS on HP Integrity | 9.2 TS1M0 | |||
Solaris for x64 | 9.2 TS1M0 |