/* $Id: simple3.sas,v 1.3 2009/06/23 19:04:52 kkleinma Exp $ */ /* These examples use the HELP data sets, available from http://www.math.smith.edu/sasr/datasets.php. The code provided in these code files reads the data sets in the various formats provided there. For smooth running, we suggest downloading all of the files available. For Windows based systems, the files should be stored in c:\data. The code in the book was run on a windows system in this configuration. For other operating systems, you will need to modify the code below to reflect different directory structures and references. */ *** Code chunk number 1 ***; proc import datafile='c:/book/help.dta' out=help_a dbms=dta; run; data help; set help_a; if female; run; *** Code chunk number 2 ***; axis1 order = (0 to 40 by 10) minor=none; axis2 minor=none; legend1 label=none value=(h=1.5) shape=symbol(10,1.2) down=3 position=(top right inside) frame mode=protect; symbol1 v=circle i=sm70s c=black l=1 h=1.1 w=5; symbol2 v=diamond i=sm70s c=black l=33 h=1.1 w=5; symbol3 v=square i=sm70s c=black l=8 h=1.1 w=5; proc gplot data=help; plot i1*age = substance / vaxis=axis1 haxis=axis2 legend=legend1; run; quit; *** Code chunk number 3 ***; *** Code chunk number 4 ***; ods output parameterestimates=helpmodelanova; proc glm data=help; class substance; model i1 = age substance age * substance / solution; output out=helpout cookd=cookd_ch4 dffits=dffits_ch4 student=sresids_ch4 residual=resid_ch4 predicted=pred_ch4 h=lev_ch4; run; quit; *** Code chunk number 8 ***; proc print data=helpmodelanova; var parameter estimate stderr tvalue probt; format _numeric_ 6.3; run; *** Code chunk number 9 ***; proc means data=helpout min q1 median q3 max maxdec=2; var resid_ch4; run; *** Code chunk number 10 ***; proc sort data=helpout; by resid_ch4; run; proc print data=helpout (obs=1); var id age i1 substance pred_ch4 resid_ch4; run; *** Code chunk number 11 ***; proc sort data=helpout; by descending resid_ch4; run; proc print data=helpout (obs=1); var id age i1 substance pred_ch4 resid_ch4; run; *** Code chunk number 12 ***; goptions reset=all; *** Code chunk number 13 ***; proc univariate data=helpout; qqplot resid_ch4 / normal(mu=est sigma=est color=black); run; *** Code chunk number 14 ***; axis1 label=("Standardized residuals"); ods select "Histogram 1"; proc univariate data=helpout; var sresids_ch4; histogram sresids_ch4 / normal(mu=est sigma=est color=black) kernel(color=black) haxis=axis1; run; *** Code chunk number 15 ***; proc sort data=help; by substance; run; ods output parameterestimates=helpsubstparams; proc glm data=help; by substance; model i1 = age / solution; run; *** Code chunk number 16 ***; proc print data=helpsubstparams; run; *** Code chunk number 17 ***; *** Note: below assumes help.sas7bdat file was downloaded and is resident in the "C:\book" directory. *** For other locations or operating systems, the "libname" statement below will have to be changed.; libname k 'c:/book'; proc sort data=k.help; by substance female; run; proc means data=k.help; by substance female; var cesd; output out=helpmean mean=; run; *** Code chunk number 18 ***; axis1 minor=none; symbol1 i=j v=none l=1 c=black w=5; symbol2 i=j v=none l=2 c=black w=5; proc gplot data=helpmean; plot cesd*substance = female / haxis=axis1 vaxis=axis1; run; quit; *** Code chunk number 19 ***; data h2; set k.help; if female eq 1 then sex='F'; else sex='M'; run; proc sort data=h2; by sex; run; symbol1 v = 'x' c = black; proc boxplot data=h2; plot cesd * substance(sex) / notches boxwidthscale=1; run; *** Code chunk number 20 ***; proc glm data=k.help; class female substance; model cesd = female substance female*substance / ss3; run; *** Code chunk number 21 ***; *** Code chunk number 22 ***; proc glm data=k.help; class female substance; model cesd = female substance / ss3 solution; run; *** Code chunk number 24 ***; proc mixed data=k.help method=ml; class female substance; model cesd = female|substance; run; quit; *** Code chunk number 25 ***; proc mixed data=k.help method=ml; class female substance; model cesd = female substance; run; quit; ods select all; *** Code chunk number 26 ***; *** Code chunk number 27 ***; proc glm data=k.help; class substance; model cesd = substance; lsmeans substance / pdiff adjust=tukey cl lines; run; quit; *** Code chunk number 30 ***; *** Code chunk number 31 ***; proc glm data=k.help; class female substance; model cesd = female substance; output out=outanova residual=resid_ch4anova; estimate 'A+H = C?' substance 1 -2 1 / e; run; quit;