pmbrown

derive_ZS.sas

Nov 11th, 2020
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /******************************************************************************
  2. Author, date: Paul Brown, JUL2015
  3. Macro name:   lrscore (calculate log rank scores for the TTE outcomes),
  4.               derive_ZS (derive the average z-score)
  5. Description:  derive the average z-score on simulated data of up to 5 outcomes.
  6.               The macro expects a dataset of &num random samples indicated by
  7.               the variable sum=1,2,...num (developed in SAS 9.4)
  8. Reference:    Evaluating Treatment Efficacy by Multiple End Points in Phase II
  9.               Acute Heart Failure Clinical Trials: Analyzing Data Using a Global Method
  10.               Sun et al. Circulation: Heart Failure, 2012
  11. ******************************************************************************/
  12.  
  13. ********************************************************************;
  14. ***                    derive log rank scores                    ***;
  15. ********************************************************************;
  16.  
  17. %macro lrscore(in_,var,cens,lrsvar);
  18. data lrstmp;
  19.   set _null_;
  20. run;
  21.  
  22. %do i=1 %to &gnum; /*do for each random sample*/
  23. proc lifetest data=&in_ (where=(samp=&i))
  24.               outsurv=outsurv plots=none noprint;
  25.   time &var*&cens(1);
  26. run;
  27.  
  28. data outsurv2;
  29.   retain survival2 ;
  30.   set outsurv (where=(survival ne 1));
  31.   if survival eq . then survival=survival2;
  32.   else survival2=survival;
  33.   if survival ne . then &var.ch=-log(survival);
  34.   else &var.ch=0; /*with sml samples sometimes no failures, z=0*/
  35.   samp=&i;
  36.   keep samp &var &var.ch;
  37. run;
  38.  
  39. proc sort data=outsurv2 nodupkey; /*duplicates if tied surv times*/
  40.   by &var;
  41. run;
  42.  
  43. data lrstmp;
  44.   set lrstmp outsurv2;
  45. run;
  46. %end;
  47.  
  48. proc sort data=&in_ (keep=samp subjno &var &cens)
  49.           out=survtimes;
  50.   by samp &var;
  51. run;
  52.  
  53. data lrs;
  54.   merge lrstmp survtimes;
  55.   by samp &var;
  56.   &lrsvar=abs(&cens-1)-&var.ch;
  57.   keep samp subjno &lrsvar;
  58. run;
  59.  
  60. proc sort data=lrs;
  61.   by samp subjno;
  62. run;
  63. %mend lrscore;
  64.  
  65.  
  66. ********************************************************************;
  67. ***                       derive z-scores                        ***;
  68. ********************************************************************;
  69.  
  70. %macro derive_ZS(indata=finalsamp,outdata=out_zs,outpval=pval_zs,
  71.                  desc1=d,desc2=d,desc3=d,desc4=,desc5=d
  72.                  /*desc: indicate whether high values are good or bad,
  73.                   for LR scores a high value is bad*/);
  74.  
  75. data readyforz;
  76.   set &indata;
  77.   keep samp subjno trt;
  78. run;
  79.  
  80. %do h=1 %to &gnumvars;
  81.   %if &&gtype&h=SURV %then %do;
  82.     %lrscore(&indata,var&h.2,var&h.c,varz&h); /*convert survival times to log rank scores*/
  83.     data readyforz;
  84.       merge readyforz lrs;
  85.       by samp subjno;
  86.       label varz&h="var&h Logrank score";
  87.     run;
  88.   %end;
  89.   %else %if &&gtype&h=LOGN %then %do;
  90.     data readyforz;
  91.       merge readyforz &indata (keep=samp subjno var&h);  
  92.       by samp subjno;
  93.       varz&h=log(1+var&h/100); /*convert from pct change to log odds*/
  94.       drop var&h;
  95.       label varz&h="var&h Log ratio";
  96.     run;
  97.   %end;
  98.   %else %do;
  99.     data readyforz;
  100.       merge readyforz &indata (keep=samp subjno var&h);  
  101.       by samp subjno;
  102.       rename var&h=varz&h;
  103.     run;
  104.   %end;
  105. %end;
  106.  
  107. *derive z-scores (for small samples and low event rates may have var=0);
  108. proc stdize data=readyforz out=zscores;
  109.   var var:;
  110.   by samp; /*not by trt*/
  111. run;
  112.  
  113. ********************************************************************;
  114. ***                  derive average z-score                  ***;
  115. ********************************************************************;
  116.  
  117. data &outdata;
  118.   set zscores;
  119.   *align z-scores (ie so high values indicate a good response);
  120.   %do h=1 %to &gnumvars;
  121.     %if &&desc&h=d %then %do;
  122.       varz&h=-varz&h;
  123.     %end;
  124.   %end;  
  125.   zscore=sum(of varz1-varz&gnumvars)/&gnumvars;
  126.   keep samp subjno trt zscore varz1-varz&gnumvars;
  127.   label zscore='Average z-score';
  128. run;
  129.  
  130. ********************************************************************;
  131. ***                   p-value                         ***;
  132. ********************************************************************;
  133.  
  134. ods output KruskalWallisTest=&outpval
  135.   (where=(name1='P_KW') keep=samp variable nValue1 name1) ;
  136. proc npar1way data=&outdata wilcoxon plots=none ;
  137.   ods select KruskalWallisTest ;
  138.   class trt;
  139.   var zscore ;
  140.   by samp;
  141. quit;
  142.  
  143. %mend derive_ZS;
  144.  
  145.  
  146.  
  147. ***end****************************************************************;
  148.  
RAW Paste Data