/********************************************************/
/* Mark.L Reyni    Testing                              */
/********************************************************/
/********************************************************/
/* Larynx cancer data from Klelin and Moeschberger. See */
/* class web page for link.  Cancers are graded on an   */
/* integer scale, with increasing numbers indicating    */
/* more sever.  Variables are stage, time to death, year*/
/* of diagnosis, and status.  On unix, run file through */
/* dos2unix.                                            */
/********************************************************/
data larynx; 
   infile '/folders/myfolders/larynx.txt' firstobs=2;
   input stage time age diagyr delta; run;
/********************************************************/
/*Two-group examples from the last lecture.             */
/********************************************************/
data stages14;
   set larynx; if stage=2 | stage=3 then delete; fs=0;
   if delta=0 and time<4.4 then fs=1;
   if delta=0 and time>7.2 then fs=1;
   if delta=1 and time<1.0 then fs=1;
   if delta=1 and time>4.0 then fs=1;
run;
data stages23; set larynx; 
   if stage<2 | stage>3 then delete; run;
%include '/folders/myfolders/fulltest.sas';
*I can't find a tool for doing the Kolmogorov-Smirnov;
*test for data with censoring in SAS.  For a macro for the;
* Renyi test see;
*www.pharmasug.org/proceedings/2011/SP/PharmaSUG-2011-SP06.pdf;
title 'Larynx Cancer Surv. Stage 2,3 Tumors by Stage';
proc lifetest data=stages23 notable;
   time time*delta(0) ; test stage; run;
* Renyi test in SAS via macro;
%fulltest(stages23,time,delta,stage);
title 'Larynx Cancer Surv. Stage 1,4 Tumors by Stage';
proc lifetest data=stages14 notable;
   time time*delta(0) ; test stage; run;
%fulltest(stages14,time,delta,stage);
title 'Larynx Cancer Surv. by artificial variable'; 
proc lifetest data=stages14 notable;
   time time*delta(0) ; test fs; run;
%fulltest(stages14,time,delta,fs);
title1 'Larynx Cancer Surv. by Stage';
proc lifetest data=larynx nocens notable;
   time time*delta(0) ; strata stage;
run;
/********************************************************/
/* Mark.K Power calculations for the log rank statistic */
/* Example from SAS manual.                             */
/********************************************************/
* Syntax for curve is time and survival probability.
* Curves with one point are exponential.;
* Accrual and followup determine censoring.  Individuals;
* are assumed accrued at random during the accrual time;
* and censored at the end of the followup time.  Subjects;
* are also lost * to followup as given by groupmedloss ;
* time.  These are medians of exponential distributions.; 
* Two values below after | give two different scenarios.;
* Parameter specified as missing is computed.;
proc power; twosamplesurvival test=logrank
  curve("Standard") = 5 : 0.5
  curve("New") = (1 to 5 by 1):(0.95 0.9 0.75 0.7 0.6)
   groupsurvival = "Standard" | "New"
   accrualtime = 2 followuptime = 3
   groupmedlosstimes = 10 | 20 5
   power = 0.8
   npergroup = . ;
run;
* Easy example.  Calculate power with hazard ratio 2.; 
* Use hazardratioand refsurvival instead of groupsurvival;
* as above.  Compare with ;
* (qnorm(.975)+qnorm(.8))^2/(log(2)^2*.5*.5*1) =65.34566;
proc power; twosamplesurvival test=logrank
     alpha=.025 sides=1
     curve("Standard") = 5 : 0.5
     refsurvival = "Standard" hazardratio =2 
     totaltime=100 followuptime=100 npergroup=.
     power= .7 .8 .9;
run;
proc power; twosamplesurvival test=logrank
     curve("Standard") = 5 : 0.5
     refsurvival = "Standard" hazardratio = 2
     totaltime=10 followuptime=10 npergroup=100
     power= .;
run;