/* $Id: simple4.sas,v 1.2 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 ***; libname k "c:/book"; data help; set k.help; run; *** Code chunk number 2 ***; *** Code chunk number 3 ***; ods select modelinfo; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 4 ***; ods select nobs; ods noproctitle; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 5 ***; ods noproctitle; ods select responseprofile; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 6 ***; ods noproctitle; ods select classlevelinfo; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 7 ***; ods noproctitle; ods select convergencestatus; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 8 ***; ods noproctitle; ods select fitstatistics; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 9 ***; ods noproctitle; ods select globaltests; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 10 ***; ods noproctitle; ods select type3; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 11 ***; options ls=74; /* keep output in grey box */ ods noproctitle; ods select parameterestimates; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 12 ***; ods noproctitle; ods select oddsratios; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; *** Code chunk number 13 ***; ods noproctitle; ods select association; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; ods proctitle; *** Code chunk number 14 ***; *** Code chunk number 15 ***; ods exclude all; ods output parameterestimates=helplogisticbetas; proc logistic data=help descending; class substance (param=ref ref='alcohol'); model homeless = female i1 substance sexrisk indtot; run; ods exclude none; options ls=74; proc print data=helplogisticbetas; run; *** Code chunk number 17 ***; *** Code chunk number 18 ***; proc genmod data=help; class substance; model i1 = female substance age / dist=poisson; run; *** Code chunk number 20 ***; *** Code chunk number 21 ***; proc genmod data=help; class substance; model i1 = female substance age / dist=zip; zeromodel female; run; *** Code chunk number 23 ***; *** Code chunk number 24 ***; proc genmod data=help; class substance; model i1 = female substance age / dist=negbin; run; *** Code chunk number 26 ***; proc quantreg data=help; class substance; model i1 = female substance age / quantile=0.75; run; *** Code chunk number 27 ***; data help3; set help; sexriskcat = (sexrisk ge 2) + (sexrisk ge 6); run; *** Code chunk number 28 ***; proc logistic data=help3 descending; model sexriskcat = cesd pcs; run; *** Code chunk number 29 ***; *** Code chunk number 30 ***; proc logistic data=help3 descending; model sexriskcat = cesd pcs / link=glogit; run; *** Code chunk number 32 ***; ods graphics on; proc gam data=help plots=components(clm); class substance; model cesd = param(female) loess(pcs) param(substance) / method=gcv; run; ods graphics off; *** Code chunk number 33 ***; /* Code below fixes apparent SAS bug with figure title */ proc template; define style Styles.Custom; parent = Styles.Printer; replace fonts / 'TitleFont' = ("Times Roman",0pt,Bold Italic) /* Titles from TITLE statements */ 'TitleFont2' = ("Times Roman",0pt,Bold Italic) /* Proc titles ("The ZZZ Procedure")*/ 'StrongFont' = ("Times Roman",0pt,Bold) ; end; run; ods pdf style = Custom; ods graphics on; ods noproctitle; proc gam data=help plots=components(clm); class substance; model cesd = param(female) loess(pcs) param(substance) / method=gcv; run; ods graphics off; ods proctitle; ods pdf close; ods graphics off; *** Code chunk number 34 ***; data long; set help; array cesd_a [4] cesd1 - cesd4; array mcs_a [4] mcs1 - mcs4; array i1_a [4] i11 - i14; array g1b_a [4] g1b1 - g1b4; do time = 1 to 4; cesdtv = cesd_a[time]; mcstv = mcs_a[time]; i1tv = i1_a[time]; g1btv = g1b_a[time]; output; end; run; *** Code chunk number 35 ***; proc freq data=long; tables g1btv*time / nocum norow nopercent; run; *** Code chunk number 36 ***; proc print data=long; where id eq 1; var id time cesd cesdtv; run; *** Code chunk number 37 ***; proc transpose data=long out=wide1 prefix=time; by notsorted id; var cesdtv mcstv i1tv g1btv; id time; run; *** Code chunk number 38 ***; proc print data=wide1 (obs=6); run; *** Code chunk number 39 ***; data wide (drop=_name_); merge wide1 (where = (_name_="cesdtv") rename = (time1=cesd1 time2=cesd2 time3=cesd3 time4=cesd4)) wide1 (where = (_name_="mcstv") rename = (time1=mcs1 time2=mcs2 time3=mcs3 time4=mcs4)) wide1 (where = (_name_="i1tv") rename = (time1=i11 time2=i12 time3=i13 time4=i14)) wide1 (where = (_name_="g1btv") rename = (time1=g1b1 time2=g1b2 time3=g1b3 time4=g1b4)); run; *** Code chunk number 40 ***; proc print data=wide (obs=2); var id cesd1 - cesd4; run; *** Code chunk number 41 ***; *** Code chunk number 42 ***; proc mixed data=long; class time; model cesdtv = treat time / solution; repeated time / subject=id type=un rcorr=7; run; *** Code chunk number 46 ***; proc sgpanel data=long; panelby time / columns=4; vbox cesdtv / category=treat ; run; *** Code chunk number 47 ***; data long2; set long; timecopy=time; run; *** Code chunk number 48 ***; *** Code chunk number 49 ***; proc sort data= long2; by id descending time; run; ods output solutionr=reffs; proc mixed data=long2 order=data; class timecopy; model cesdtv = treat timecopy / solution; random int time / subject=id type=un vcorr=20 solution; run; *** Code chunk number 53 ***; *** Code chunk number 54 ***; proc print data=reffs; where strip(subject) eq '1'; run; *** Code chunk number 55 ***; proc mixed data=long2 order=data; class timecopy; model cesdtv = treat timecopy / outp=lmmp outpm=lmmpm; random int time / subject=id type=un; run; *** Code chunk number 56 ***; data lmmout; merge lmmp lmmpm (rename = (pred=margpred)); by id descending time; run; proc print data=lmmout; where id eq 1; var id time cesdtv pred margpred; run; *** Code chunk number 57 ***; *** Code chunk number 58 ***; *** Code chunk number 59 ***; proc genmod data=long2 descending; class id; model g1btv = treat time / dist=bin; repeated subject = id / type=exch corrw; run; *** Code chunk number 61 ***; proc glimmix data=long; model g1btv = treat cesdtv time / dist=bin solution; random int / subject=id; run; *** Code chunk number 63 ***; *** Code chunk number 64 ***; proc phreg data=help; class treat female; model dayslink*linkstatus(0) = treat age female cesd; run;