Wednesday, March 13, 2019

Add shade to Kaplan Meier plot

data km;
  seed=12345;
  do loc=1 to 2;
    do time=2 to 22 by 1+int(4*ranuni(seed));
      status=int(2*ranuni(seed));
      output;
    end;
  end;
run;

proc lifetest data=km plots=s outsurv=os;
  ods select survivalplot;
  time time*status(1);
  strata loc;
run;

data os;
  retain survhold 1;
  set os;
  if _censor_ = 1 then  SURVIVAL= survhold;
  else survhold= SURVIVAL;
run;

proc sgplot data=os;
  step x=time y=Survival / name="survival" legendlabel="Survival" group=stratum;
  band x=time lower=0 upper=survival / modelname="survival" transparency=.5;
run;