Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Author, date: Paul Brown, SEP2015
- Macro name: derive_WR
- Description: derive the unmatched win-ratio endpoint on simulated data.
- (developed in SAS 9.4)
- Reference: The win ratio: a new approach to the analysis of composite
- endpoints in clinical trials based on clinical priorities,
- Pocock SJ et al., EHJ, 2012
- ******************************************************************************/
- ********************************************************************;
- *** Rank survival times and count ties ***;
- ********************************************************************;
- %macro surv_wr(indata_,var,where);
- proc sort data=&indata_ (where=&where) out=&var;
- by samp &var;
- run;
- data rank&var;
- retain ties&var before&var count 0;
- set &var;
- by samp &var;
- if first.samp then count=0;
- else count=count+1;
- if first.&var then do;
- ties&var=1;
- before&var=count; /*can check using ties=low option in proc rank*/
- end;
- else ties&var=ties&var+1;
- keep samp subjno trt &var ties&var before&var;
- run;
- proc sort data=rank&var out=ties&var (keep=samp &var ties&var);
- by samp &var descending ties&var;
- run;
- proc sort data=ties&var nodupkey;
- by samp &var ;
- run;
- data rank&var.2;
- merge rank&var (drop=ties&var) ties&var;
- by samp &var;
- run;
- proc sort data=rank&var.2;
- by samp subjno;
- run;
- %mend surv_wr;
- ********************************************************************;
- *** Derive win-ratio score (U) ***;
- ********************************************************************;
- %macro derive_wr(n=100,indata=finalsamp,outdata=out_wr,outpval=pval_wr);
- %surv_wr(&indata,var1,(var1c=0));
- %surv_wr(&indata,var2,(var1c=1 and var2c=0)); /*consider reh for pts who didnt die*/
- *consider where pts fail;
- data winratio;
- merge &indata rankvar12 rankvar22;
- by samp subjno trt;
- if var1c=0 then cat=1; /*pt died*/
- else if var2c=0 then cat=2; /*pt didnt die, had rehosp*/
- else cat=3;
- run;
- *find the number of pts falling into these broad categories to enable
- calculation of no. of wins/losses/ties per pt;
- ods output onewayfreqs=counts1;
- proc freq data=winratio;
- ods select onewayfreqs;
- tables cat ;
- by samp;
- run;
- proc transpose data=counts1 out=counts1_t (drop=_name_) prefix=cat;
- var frequency;
- id cat;
- by samp;
- run;
- *replace missings obs with 0 (when n small have small or missing cell counts);
- proc stdize data=counts1_t
- out=counts1_t2 reponly missing=0;
- run;
- *calculate number of wins/losses/ties for each pt, ie as if comparing each
- pt to every other pt (irrespective of trt group) as per the unmatched approach;
- data &outdata;
- merge winratio counts1_t2 ;
- by samp;
- if cat=1 then do; /*compare mortality times*/
- win=beforevar1;
- tie=tiesvar1-1; /*subtract 1 so the pt isnt tied with themselves*/
- lose=(&n-1)-win-tie;
- end;
- else if cat=2 then do; /*cant determine who died 1st, use rehosp*/
- win=cat1+beforevar2;
- tie=tiesvar2-1;
- lose=(&n-1)-win-tie;
- end;
- else if cat=3 then do; /*cant determine who died 1st, use rehosp*/
- win=cat1+cat2;
- tie=cat3-1;
- lose=(&n-1)-win-tie;
- end;
- check=win+lose+tie; /*check sum to n-1*/
- u=win-lose; /*ties have zero weight*/
- u2=u**2;
- keep samp subjno trt win lose tie u u2 check ;
- label win='No. of wins' lose='No of losses' tie='No. of ties'
- u='Win-ratio U (sum of wins/losses/ties)' u2='U^2 (for var of test stat)'
- check='Sum of wins/losses/ties (use as a check)';
- run;
- proc sort data=&outdata;
- by samp subjno;
- run;
- ********************************************************************;
- *** p-value ***;
- ********************************************************************;
- *calculate the p-value by hand for the unmatched win ratio
- (see Finkelstein and Schoenfeld, and pocock stat appendix: the U^2
- and U are summed for the active grp. NOTE: there is a typo in
- their variance eqn i.e. it should sum U^2 from 1 to N, not 1 to n);
- proc univariate data=&outdata (where=(trt='Active'));
- var u ;
- by samp;
- output out=usum sum=usum;
- run;
- proc univariate data=&outdata;
- var u2;
- by samp;
- output out=u2sum sum=u2sum;
- run;
- data &outpval;
- merge usum u2sum;
- by samp;
- T=usum; /*sum of U for active trt group*/
- V=(&n/2)*(&n/2)/(&n*(&n-1))*u2sum; /*variance of T*/
- Z=T/sqrt(V);
- nValue1=2*(1-probnorm(abs(Z))); /*p-value*/
- run;
- %mend derive_wr;
- ***end****************************************************************;
RAW Paste Data