/* oct30.ex2 */ /* */ /* two sample problem from ST430 */ /* */ /* Differences in blood pressure */ /* */ /* sbp = systolic blood pressure (lbs/sq in) */ /* smoke = smoker (yes) or not (no) */ /* group = group id (1=nonsmoker, 2=smoker) */ /* */ data a ; input sbp smoke $ group ; /* ^ says character variable */ cards ; 133 no 1 122 no 1 130 no 1 148 no 1 142 no 1 146 yes 2 137 yes 2 162 yes 2 160 yes 2 144 yes 2 173 yes 2 166 yes 2 138 yes 2 140 yes 2 134 yes 2 ; run ; /* two sample t-test */ proc ttest data=a ; class group ; * smoke would work in the same way ; var sbp ; * what variable? ; run ; /* permutation distribution is random assignment */ /* of individual to groups -- with same totals */ %let krep = 20 ; * macro variable ; %let m = 5 ; * one group ; %let n = 10 ; * other group ; %let mpn = %eval(&m + &n) ; * total ; data aperm ; array pj(&krep) ; retain pj1-pj&krep &m _all_ ; * initial value ; keep group k sbp ; set a ; seed = 5151917 ; do k = 1 to &krep ; if( ranuni(seed) lt pj(k)/(&mpn-_n_+1) ) then do ; group = 1 ; pj(k) = pj(k) - 1 ; end ; else group = 2 ; output ; * make obs ; end ; * of loop on k ; run ; /* now analyze each one */ /* */ /* first sort by replication counter */ proc sort data=aperm ; by k ; run ; /* */ /* now compute statistic */ * ods listing close ; ****** maybe not yet ; proc ttest data=aperm ; class group ; * two groups, 1 & 2 ; var sbp ; * analyze blood p ; by k ; * replication ; ods output TTests=tds ; run ; ods listing ; /* what's in this ds? */ proc print data=tds (obs=10) ; title 'ods dataset' ; run ;