12:13 Tuesday, September 23, 2003 9

Week 5 [24 Sept., 26 Sept.] Class Activities

C:\Documents and Settings\John Bailer\My Documents\baileraj\Classes\Fall 2003\sta402\handouts\week5-23sep03.doc

HIGH-RESOLUTION GRAPHICS AND FORMATS

* Introduce concepts related to high-resolution graphs

* PROC GCHART and PROC GPLOT for producing high-resolution graphs

other SAS high resolution graphics procedures …

GCHART (bar charts, pie charts, star charts)

GPLOT (line plot, scatter plot, regression plot, high-low plots, bubble plots)

G3D (3-dimensional surface plots)

GCONTOUR, G3GRID (interpolate/smooth data)

GMAP (block, choropleth, prism, surface)

GSLIDE (create text slide)

GPRINT (display as a graphic SAS procedure output that has been saved in a text file)

GREPLAY (combine several graphs into a single output)

To list all graphics devices in the current catalog …

proc gdevice catalog=sashelp.devices nofs;

list;

run;

* SAS-supplied formats and PROC FORMAT for user-defined formats

References

http://www.units.muohio.edu/doc/sassystem/sasonlinedocv8/sasdoc/sashtml/main.htm

GPLOT figures

/*

example sas program that does simple linear regression

*/

libname class 'D:\baileraj\Classes\Fall 2003\sta402\data’;

options ls=75;

data class.manatee;

input year nboats manatees;

cards;

77 447 13

78 460 21

79 481 24

80 498 16

81 513 24

82 512 20

83 526 15

84 559 34

85 585 33

86 614 33

87 645 39

88 675 43

89 711 50

90 719 47

;

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig1.rtf’;

proc gplot data=class.manatee;

title ‘Number of Manatees killed regressed on the number of boats registered in Florida’;

plot manatees*nboats;

run;

ODS RTF CLOSE;

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig1a.rtf';

proc gplot data=class.manatee;

title h=1.5 'A plot of the number of manatee deaths versus the number of boats registered in Florida';

title2 h=1 '[Regression line with CI for mean along with smoothing spline fit displayed]';

symbol1 interpol=rlclm95

/* r=regression, l=linear (q,c also possible), clm=conf. int. mean (cli option), 95= conf. level */

value=diamond

height=3

cv=red

ci=blue

co=green

width=2;

symbol2 interpol=SM55s

/* smoothing spline (SM) that first sorts the x-axis data */

;

plot manatees*nboats manatees*nboats /

hminor=1

overlay

regeqn; /* adds regression eqn to bottom left of plot */

run;

ODS RTF CLOSE;

libname class 'D:\baileraj\Classes\Fall 2003\sta402\data’;

proc format;

value totfmt 0='none'

1-HIGH='some'

;

/* creates a permanent dataset with the nitrofen data */

data class.nitrofen;

infile 'M:\public.www\classes\sta402\SAS-programs\ch2-dat.txt' firstobs=16 expandtabs missover pad ;

input @9 animal 2.

@17 conc 3.

@25 brood1 2.

@33 brood2 2.

@41 brood3 2.

@49 total 2.;

/* creates character variable based on format */

cbrood3 = put(brood3,totfmt.);

label animal = animal ID number;

label conc = Nitrofen concentration;

label brood1 = number of young in first brood;

label brood2 = number of young in 2nd brood;

label brood3 = number of young in 3rd brood;

*label total = total young produced in three broods;

proc print data=class.nitrofen;

run;

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig2.rtf';

/* SYMBOL = defines characteristics of plotted symbols */

proc gplot data=class.nitrofen;

title h=1.5 'A plot of the number of C. dubia produced at different Nitrofen concentrations';

title2 h=1 '[mean +/- 2SD is plotted for each concentration]';

symbol1 interpol=STD2T /* plots +/- 2 SD from the mean at each conc */

/* T= add top and bottom to each 2 SD diff */

value=dot;

plot total*conc / hminor=1 /* hminor=# tick markets before x values */

haxis=0 to 350 by 50;

run;

ODS RTF CLOSE;

proc means data=class.nitrofen;

class conc;

var total;

output out=nitromean mean=n_mean stddev=n_sd;

run;

proc print;

run;

Obs conc _TYPE_ _FREQ_ n_mean n_sd

1 . 0 50 22.88 10.7241

2 0 1 10 31.40 3.5963

3 80 1 10 31.50 3.2745

4 160 1 10 28.30 2.3594

5 235 1 10 17.20 5.9029

6 310 1 10 6.00 3.7118

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig3.rtf';

proc gplot data=nitromean;

title h=1.5 'Plot of mean number of C. dubia young produced at different Nitrofen concentrations';

title2 h=1 '[bubble area proportional to std dev.]';

bubble n_mean*conc=n_sd / bsize=15; /* bsize helps resize bubble for display */

run;

ODS RTF CLOSE;

GCHART figures

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig4.rtf';

goptions reset=global gunit=pct border cback=white

colors=(black blue green red) ftext=swiss

ftitle=swissb htitle=5 htext=3.5;

title1 'Average Total Young by Nitrofen concentration';

axis1 label=('Total Young' j=c

'Error Bar Confidence Limits: 95%')

minor=(number=1);

axis2 label=('Nitrofen' j=r 'Concentration');

pattern1 color=cyan;

proc gchart data=class.nitrofen;

hbar conc / type=mean

sumvar=total

/* freqlabel='Number in Group' */

/* meanlabel='Mean Number Young' */

errorbar=bars

clm=95

midpoints=(0 80 160 235 310)

raxis=axis1

maxis=axis2

noframe

coutline=black;

run;

ODS RTF CLOSE;

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig5.rtf';

proc gchart data=class.nitrofen;

title1 'Total Young by Nitrofen concentration';

star conc / sumvar=total;

run;

proc gchart data=class.nitrofen;

title1 'Total Young by Nitrofen concentration';

pie conc / sumvar=total;

run;

ODS RTF CLOSE;

12:13 Tuesday, September 23, 2003 21

Two-way ANOVA/ Factorial example 2 - interaction plots
Patient Waiting Time data
The GLM Procedure
Tukey's Studentized Range (HSD) Test for time

GREPLAY figures

/* now trying something fancy using templates and GREPLAY

to get multiple figures on a page

REF:

http://www.units.muohio.edu/doc/sassystem/sasonlinedocv8/sasdoc/sashtml/gref/z61-ex.htm

*/

libname class 'D:\baileraj\Classes\Fall 2003\sta402\data’;

/* libname class previously defined */

goptions reset=global gunit=pct border cback=white

colors=(black blue green red)

ftext=swissb htitle=6 htext=3;

proc greplay tc=class.tempcat nofs;

tdef newtemp des='Five panel template'

1/llx=0 lly=10

ulx=0 uly=50

urx=50 ury=50

lrx=50 lry=10

color=blue

2/llx=0 lly=50

ulx=0 uly=90

urx=50 ury=90

lrx=50 lry=50

color=red

3/llx=50 lly=50

ulx=50 uly=90

urx=100 ury=90

lrx=100 lry=50

color=green

4/llx=50 lly=10

ulx=50 uly=50

urx=100 ury=50

lrx=100 lry=10

color=cyan;

template newtemp;

list template;

quit;

proc gplot data=class.nitrofen gout=class.graph;

title c=red 'Brood 1';

plot brood1*conc;

run;

title 'Brood 2';

plot brood2*conc;

run;

title 'Brood 3';

plot brood3*conc;

run;

title 'TOTAL';

plot total*conc;

run;

goptions hsize=0in vsize=0in;

proc gslide gout=class.graph;

title 'PLOT of brood and total responses versus nitrofen concentration';

run;

goptions display;

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig6.rtf';

proc greplay igout=class.graph gout=class.excat

tc=class.tempcat nofs

template=newtemp;

treplay 3:gplot2 /* plot bottom left - brood 3 */

1:gplot /* top left - brood 1 */

2:gplot1 /* top right - brood 2 */

4:gplot3 ; /* bottom right - total */

quit;

ODS RTF CLOSE;

G3D figures

libname class 'D:\baileraj\Classes\Fall 2003\sta402\data’;

data new; set class.nitrofen;

retain conc;

brood=1; young=brood1; output;

brood=2; young=brood2; output;

brood=3; young=brood3; output;

keep conc brood young;

data new2; set new;

jconc = conc + (10-20*ranuni(0));

jbrood = brood + (1-2*ranuni(0));

run;

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig7.rtf';

proc g3d data=new2;

title h=1 ‘Scatter plot of # young by conc. and brood (jittered)’;

scatter jconc*jbrood=young / xticknum=2 yticknum=2;

run;

quit;

ODF RTF CLOSE;

proc means data=new;

class conc brood;

var young;

output out=new3 mean=ymean;

run;

ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig8.rtf';

proc g3d data=new3;

title h=1 'Surface plot of mean # young by conc. and brood';

plot conc*brood=ymean / xticknum=2 yticknum=2 tilt=80;

run;

quit;

ODS RTF CLOSE;

FORMATTING

Formats

Informats

Internal formats