/* $Id: simple2.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 ***; filename myurl url 'http://www.math.smith.edu/sasr/datasets/help.csv' lrecl=704; proc import datafile=myurl out=ds dbms=dlm; delimiter=','; getnames=yes; run; *** Code chunk number 2 ***; proc means data=ds maxdec=2 min p5 q1 median q3 p95 max mean std range; var cesd; run; *** Code chunk number 3 ***; proc univariate data=ds; var cesd; output out=deciles pctlpts= 0 to 100 by 10 pctlpre=p_; run; proc print data=deciles; run; *** Code chunk number 4 ***; proc univariate data=ds; var cesd; histogram cesd / normal (color=black l=1) kernel(color=black l=21) cfill=greyCC; run; quit; *** Code chunk number 5 ***; proc corr data=ds; var cesd mcs pcs; run; *** Code chunk number 6 ***; proc corr data=ds; var mcs pcs; with cesd; run; *** Code chunk number 7 ***; symbol1 font=swiss v='A' h=.7 c=black; symbol2 font=swiss v='C' h=.7 c=black; symbol3 font=swiss v='H' h=.7 c=black; proc gplot data=ds; where female=1; plot mcs*cesd=substance; run; quit; *** Code chunk number 9 ***; ods select crosstabfreqs; proc freq data=ds; tables homeless*female / chisq exact relrisk; run; quit; *** Code chunk number 13 ***; options ls=74; /* narrows output to stay in the grey box */ proc ttest data=ds; class female; var age; run; *** Code chunk number 14 ***; ods output kolsmir2stats=age_female_ks_stats; proc npar1way data=ds; class female; var age; exact scores=data / mc n=9999 alpha=.05; run; *** Code chunk number 18 ***; proc sort data=ds; by female; run; proc kde data=ds; by female; univar age / out=kdeout; run; *** Code chunk number 19 ***; proc print data=age_female_ks_stats; run; *** Code chunk number 20 ***; data _null_; set age_female_ks_stats; if label2 eq 'D' then call symput('dvalue', substr(cvalue2, 1, 5)); /* This makes a macro variable (which is saved outside any dataset) from a value in a dataset */ if label2 eq 'Pr > KSa' then call symput('pvalue', substr(cvalue2, 1, 4)); run; *** Code chunk number 21 ***; *** Code chunk number 22 ***; symbol1 i=j w=5 l=1 v=none c=black; symbol2 i=j w=5 l=2 v=none c=black; pattern1 color=grayBB; proc gplot data=kdeout; note justify=center height=1.15 "Test of ages: D=&dvalue p=&pvalue"; /* note: prior line substituted for title statement due to difficulty with the otherwise excellent software used to get SAS code and output to generate LaTeX files. Results should be quite similar with the printed book code */ plot density*value = female / legend areas=1 haxis=18 to 60 by 2; run; *** Code chunk number 23 ***; proc lifetest data=ds; time dayslink*linkstatus(0); strata treat; run;