/* The RAND_GEN macro code appears on page 100 in the book, "SAS(R) Survival Analysis Techniques for Medical Research, Second Edition" by Alan B. Cantor, Ph.D. */ %macro rand_gen( indata= , time = , cens = , group = , numreps=1000, seed=0); %let indata=&indata; /* forces evaluation of &INDATA at the right time */ /* Get size of input dataset into macro variable &NUMRECS */ proc sql noprint; select count(*) into :numrecs from &INDATA; quit; /* Generate &NUMREPS random numbers for each record, so records can be randomly sorted within each replicate */ data __temp_1; retain seed &SEED ; drop seed; set &INDATA; do replicate = 1 to &NUMREPS; call ranuni(seed,rand_dep); output; end; run; proc sort data=__temp_1; by replicate rand_dep; run; /* Now append the new re-orderings to the original dataset. Label the original as Replicate=0, so the %TEST macro will be able to pick out the correct p-value. Then use the ordering of __counter within each replicate to write the original values of &time and &cens, thus creating a randomization of these variables in every replicate. */ data reps ; array timelist{ &NUMRECS } _temporary_ ; array censlist{ &NUMRECS } _temporary_; set &INDATA(in=in_orig) __temp_1(drop=rand_dep); if in_orig then do; replicate=0; timelist{_n_} = &time ; censlist{_n_} = &cens ; end; else do ; &time = timelist{ 1+ mod(_n_,&NUMRECS) }; &cens = censlist{ 1+mod(_n_, &NUMRECS) }; end; run; %mend rand_gen;