/*The TEST macro code appears on page 102 in the book, "SAS(R) Survival Analysis Techniques for Medical Research, Second Edition" by Alan B. Cantor, Ph.D. */ %macro test(time = , cens = , censval = , test = , group = , type = ); proc lifetest data = reps outtest = out noprint; time &time*&cens(&censval); test &group; by replicate; run; data out2 ; set out; if "&test" = 'logrank' then type = 'LOG RANK'; if "&test" = 'gehan' then type = 'WILCOXON'; if _TYPE_ = type and _NAME_ = "&time" then output; data out3; set out2 end = last; retain chisq; if replicate = 0 then chisq = &time; else do; if &time + .00000001 ge chisq then num+1; end; if last then do; pvalue = num/(_n_ - 1); stderr = sqrt((pvalue*(1-pvalue))/(_n_ - 1)); lowbound = max(pvalue - 1.96*stderr, 0); upperbound = min(pvalue + 1.96*stderr, 1); n = _n_ - 1; output; end; %if &type = rand %then %do; label n = 'Number of Replicates'; label pvalue = "Randomization &test Test Estimated P-Value (2-sided)"; label lowbound = 'Lower 95 Pct Bound'; label upperbound = 'Upper 95 Pct Bound'; %end; %else %do; label pvalue = "Permutation &test Test P-Value (2-sided)"; %end; %if &type = rand %then %do; proc print noobs l; var pvalue stderr lowbound upperbound n; %end; %else %do; proc print noobs l ; var pvalue; %end; run; data; set out2; if replicate = 0; p = 1 - probchi(&time, 1); label p = 'Asymptotic P-Value'; proc print noobs l ; var p; run; %mend;