The sample code on the Full Code tab illustrates how to use an Annotate data set to display mean and median values on a box plot generated with the GPLOT procedure.
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.
The graphics output on the Results tab was produced using SAS® 9.3. Submitting the sample code with releases of SAS prior to SAS 9.3 might produce different results.
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
/* Create a sample data set to plot */
data one(drop=i);
do i=1 to 10;
do xvar=1 to 9 by 2;
yvar=ranuni(0)*100;
output;
end;
end;
run;
/* Sort the data by XVAR */
proc sort data=one;
by xvar;
run;
/* Use the UNIVARIATE procedure to determine */
/* the mean and median values */
proc univariate data=one noprint;
var yvar;
by xvar;
output mean=mean median=median out=stat;
run;
/* Merge the mean and median values back */
/* into the original data set by XVAR */
data all;
merge one stat;
by xvar;
run;
/* Create an annotate data set to generate */
/* labels for the mean and median values */
data anno;
set all;
by xvar;
length function color text $8;
retain color 'black' when 'a' position '6' size 1.5;
if first.xvar then do;
function='move'; xsys='2'; ysys='2';
x=xvar; y=mean; output;
function='cntl2txt'; output;
function='label'; xsys='A'; x=+3;
text=trim(left(put(mean,8.1))); output;
function='move'; xsys='2'; ysys='2';
x=xvar; y=median; output;
function='cntl2txt'; output;
function='label'; xsys='A'; x=+3;
text=trim(left(put(median,8.1))); output;
end;
run;
/* Reshape the data set to create a category */
/* variable to use to generate the legend */
data reshape;
set all;
length zvar $8;
newy=yvar; zvar='Box'; output;
newy=mean; zvar='Mean'; output;
newy=median; zvar='Median'; output;
run;
/* Define a title for the graph */
title1 "Display Mean and Median Values on a Box Plot";
/* Define SYMBOL characteristics */
symbol1 interpol=boxft cv=LightSeaGreen co=black value=none bwidth=5 mode=include;
symbol2 interpol=none color=depk height=1.8 value=dot;
symbol3 interpol=none color=mob height=1.8 value=diamondfilled;
/* Define legend characteristics */
legend1 order=('Mean' 'Median') repeat=1
label=none frame shape=symbol(1.8,1.8);
/* Create the graph */
proc gplot data=reshape;
plot newy*xvar=zvar / legend=legend1
haxis=0 to 10 by 1
annotate=anno;
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 ==> Annotation Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Plots ==> Other Plots |
Date Modified: | 2012-06-01 12:08:09 |
Date Created: | 2012-06-01 10:42:03 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/GRAPH | z/OS | 9.3 TS1M0 | |
Microsoft® Windows® for x64 | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 for x64 | 9.3 TS1M0 | |||
Microsoft Windows Server 2008 | 9.3 TS1M0 | |||
Microsoft Windows Server 2008 for x64 | 9.3 TS1M0 | |||
Microsoft Windows XP Professional | 9.3 TS1M0 | |||
Windows 7 Enterprise 32 bit | 9.3 TS1M0 | |||
Windows 7 Enterprise x64 | 9.3 TS1M0 | |||
Windows 7 Home Premium 32 bit | 9.3 TS1M0 | |||
Windows 7 Home Premium x64 | 9.3 TS1M0 | |||
Windows 7 Professional 32 bit | 9.3 TS1M0 | |||
Windows 7 Professional x64 | 9.3 TS1M0 | |||
Windows 7 Ultimate 32 bit | 9.3 TS1M0 | |||
Windows 7 Ultimate x64 | 9.3 TS1M0 | |||
Windows Vista | 9.3 TS1M0 | |||
Windows Vista for x64 | 9.3 TS1M0 | |||
64-bit Enabled AIX | 9.3 TS1M0 | |||
64-bit Enabled HP-UX | 9.3 TS1M0 | |||
64-bit Enabled Solaris | 9.3 TS1M0 | |||
HP-UX IPF | 9.3 TS1M0 | |||
Linux | 9.3 TS1M0 | |||
Linux for x64 | 9.3 TS1M0 | |||
Solaris for x64 | 9.3 TS1M0 |