pmbrown

derive_GR.sas

Nov 11th, 2020
28
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /******************************************************************************
  2. Author, date: Paul Brown, JUL2015
  3. Macro name:   derive_GR
  4. Description:  derive the global rank endpoint on simulated data of up to 5 outcomes.
  5.               (developed in SAS 9.4)
  6. Reference:    A Global Rank End Point for Clinical Trials in Acute Heart Failure,
  7.               Felker GM, Maisel AS, Circulation: Heart Failure, 2010
  8. ******************************************************************************/
  9.  
  10. %macro derive_GR(indata=finalsamp,outdata=out_gr,outpval=pval_gr,
  11.                  cut1=30,cut2=30,cut3=1,cut4=936,cut5=30,
  12.          /*cut: cut-offs defining failure (for dichotomous outcome cut-off = 1)*/
  13.                  desc1=,desc2=,desc3=d,desc4=,desc5=d,
  14.         /*desc: indicate whether high values are good or bad, ie how to sort data*/
  15.                  ord1=1,ord2=2,ord3=3,ord4=4,ord5=5);
  16.            /*ord: indicates position of outcome in hierarchy*/    
  17.  
  18. ********************************************************************;
  19. ***              Identify and rank failures                      ***;
  20. ********************************************************************;
  21.  
  22. %do h=1 %to &gnumvars;
  23.  
  24. proc sort data=&indata out=out&h (keep=samp subjno trt var&h);
  25.   %if &&desc&h=d %then %do;
  26.     by samp descending var&h;
  27.   %end;
  28.   %else %do;
  29.     by samp var&h;
  30.   %end;
  31. run;
  32.  
  33. data out2&h;
  34.   format param $20. valuen best.;
  35.   retain rank 0;
  36.   set out&h;
  37.   %if &&desc&h=d %then %do;
  38.     by samp descending var&h;
  39.     if var&h ge &&cut&h then fail=1;
  40.   %end;
  41.   %else %do;
  42.     by samp var&h;
  43.     if var&h le &&cut&h then fail=1;
  44.   %end;
  45.   ord=&&ord&h;
  46.   param="&&gtype&h"||"&h";
  47.   valuen=var&h;
  48.   if first.samp then rank=0;
  49.   if first.var&h then rank=rank+1;
  50.   keep samp subjno trt ord rank param valuen fail;
  51. run;
  52.  
  53. proc sort data=out2&h ;
  54.   by samp subjno;
  55. run;
  56.  
  57. %end;
  58.  
  59. ********************************************************************;
  60. ***                   derive global rank                         ***;
  61. ********************************************************************;
  62.  
  63. *calculate temporary score to be ranked below;
  64. data globrnk;
  65.   set out21-out2&gnumvars;
  66.   if fail=1 and ord ne &gnumvars then
  67.     globrnk_tmp=ord*1000+rank; /*1000=arbitrarily large number, must be >> n*/
  68.   /*rank non-fails on last outcome*/
  69.   else if ord=&gnumvars then globrnk_tmp=&gnumvars*1000+rank;
  70.   /*remove data not failing and not belonging to last endpt*/
  71.   else delete;
  72.   label ord='Position in hierarchy' rank='Rank within outcome'
  73.         param='Outcome ranked on' valuen='Value';
  74. run;
  75.  
  76. proc sort data=globrnk;
  77.   by samp subjno globrnk_tmp;
  78. run;
  79.  
  80. proc sort data=globrnk out=globrnk2 nodupkey;
  81.   by samp subjno ;
  82. run;
  83.  
  84. proc sort data=globrnk2;
  85.   by samp globrnk_tmp;
  86. run;
  87.  
  88. *assign global ranks;
  89. data globrnk3;
  90.   retain globrnk 0 ;
  91.   set globrnk2;
  92.   by samp globrnk_tmp;
  93.   if first.samp then globrnk=0;
  94.   if first.globrnk_tmp then globrnk=globrnk+1;
  95.   label globrnk='Global Rank';
  96. run;
  97.  
  98. proc sort data=globrnk3;
  99.   by samp subjno;
  100. run;
  101.  
  102. *put variables in a suitable order ;
  103. data &outdata;
  104.   retain samp subjno trt param valuen rank globrnk ;
  105.   set globrnk3;
  106.   keep samp subjno trt param valuen rank globrnk ;
  107. run;
  108.  
  109. ********************************************************************;
  110. ***                   p-value                         ***;
  111. ********************************************************************;
  112.  
  113. ods output KruskalWallisTest=&outpval
  114.   (where=(name1='P_KW') keep=samp variable nValue1 name1) ;
  115. proc npar1way data=&outdata wilcoxon plots=none ;
  116.   ods select KruskalWallisTest ;
  117.   class trt;
  118.   var globrnk ;
  119.   by samp;
  120. quit;
  121.  
  122. %mend derive_GR;
  123.  
  124.  
  125. ***end****************************************************************;
  126.  
RAW Paste Data