Hello,
I need like to smooth my kaplan-meier curves and I do not know how proceed. Here is an example of my data:
data have;
input
id time1 event1 weight;
datalines;
1 0 0 0.8
1 1 0 0.8
1 2 0 0.8
1 3 0 0.8
1 4 0 0.8
15 0 0.8
1 6 0 0.8
1 7 0 0.8
1 8 0 0.8
1 9 0 0.8
1 10 0 0.8
1 11 0 0.8
1 12 0 0.8
1 13 0 0.8
2 0 0 1.1
2 1 1 1.1
2 2 . 1.1
3 0 0 1.01
3 1 0 1.01
3 2 1 1.01
3 3 . 1.01
4 0 1 0.98
4 1 . 0.98
4 2 . 0.98
4 3 . 0.98
4 4 . 0.98
5 0 0 1.13
6 0 0 1.05
6 1 0 1.05
6 2 0 1.05
6 3 0 1.05
6 4 0 1.05
6 5 1 1.05
6 6 . 1.05
6 7 . 1.05
6 8 . 1.05
7 0 0 0.89
7 1 0 0.89
7 2 0 0.89
7 3 0 0.89
7 4 0 0.89
7 5 0 0.89
7 6 0 0.89
7 7 0 0.89
7 8 1 0.89
7 9 . 0.89
7 10 . 0.89
8 0 0 1.1
8 1 0 1.1
8 2 0 1.1
8 3 . 1.1
8 4 . 1.1
;
run;
This is an example of my proc lifetest procedure:
proc lifetest method=KM data=have atrisk plots=(s) notable;
time time1*event1(0);
weight weight;
run;
Does anyone know how I could make it ?
In the LOESS staement, move your BY variable to a GROUP variable instead and specify the NOMARKERS option to remove the individual points. Both are listed as options in the documentation.
Note that your code generates errors in the log regarding PROC LIFETEST.
WARNING: 'ProductLimitSurvival' was compiled using a different
version of SAS.
This might result in unexpected behavior.
WARNING: Insufficient data to produce
'Stat.Lifetest.Graphics.ProductLimitSurvival' Graph.
@MFraga wrote:
No, not a homework not done because I had read before the topic you are pointing and the answer is not clear. I just need the survival smoothed curve graphic and I do not want to have the dots of my observations in the graphic.
In other topic, you said that "You can get the output from the PROC LIFETEST and then apply a LOESS statement within SGPLOT to plot the data instead of using the default SAS output".
So, following what you suggested, I coded like this (I am adding a new data because I need to stratify by some variables):
data have;
input
id time1 event1 weight var1;
datalines;
1 0 0 0.8 0
1 1 0 0.8 0
1 2 0 0.8 0
1 3 0 0.8 0
1 4 0 0.8 0
1 5 0 0.8 0
1 6 0 0.8 0
1 7 0 0.8 0
1 8 0 0.8 0
1 9 0 0.8 0
1 10 0 0.8 0
1 11 0 0.8 0
1 12 0 0.8 0
1 13 0 0.8 0
2 0 0 1.1 2
2 1 1 1.1 2
2 2 . 1.1 2
3 0 0 1.01 2
3 1 0 1.01 2
3 2 1 1.01 2
3 3 . 1.01 2
4 0 1 0.98 1
4 1 . 0.98 1
4 2 . 0.98 1
4 3 . 0.98 1
4 4 . 0.98 1
5 0 0 1.13 1
6 0 0 1.05 1
6 1 0 1.05 1
6 2 0 1.05 1
6 3 0 1.05 1
6 4 0 1.05 1
6 5 1 1.05 1
6 6 . 1.05 1
6 7 . 1.05 1
6 8 . 1.05 1
7 0 0 0.89 0
7 1 0 0.89 0
7 2 0 0.89 0
7 3 0 0.89 0
7 4 0 0.89 0
7 5 0 0.89 0
7 6 0 0.89 0
7 7 0 0.89 0
7 8 1 0.89 0
7 9 . 0.89 0
7 10 . 0.89 0
8 0 0 1.1 1
8 1 0 1.1 1
8 2 0 1.1 1
8 3 . 1.1 1
8 4 . 1.1 1
;
run;
proc lifetest method=km data=have outsurv=km atrisk plots=(s) notable;
time time1*event1(0);
strata var1;
weight weight;
run;
proc sgplot data=km noautolegend;
loess x=time1 y=survival;
by var1;xaxis values=(0 to 13 by 1);
yaxis values=(0 to 1 by 0.1);run;
So, I have as output 3 graphics with the survival curves for each level of "var1". What I really need one graphic that outputs all the levels of var1 curves at the same graphic.
If I use the a life-table estimate, I have what I want, but life-table (lt) does not work with weighting, so not what I need neither.
proc lifetest data=have method=lt intervals=(0 to 13 by 1) atrisk plots=(s);
time time1*event1(0);
strata var1;
run;
So any help?
No, not a homework not done because I had read before the topic you are pointing and the answer is not clear. I just need the survival smoothed curve graphic and I do not want to have the dots of my observations in the graphic.
In other topic, you said that "You can get the output from the PROC LIFETEST and then apply a LOESS statement within SGPLOT to plot the data instead of using the default SAS output".
So, following what you suggested, I coded like this (I am adding a new data because I need to stratify by some variables):
data have;
input
id time1 event1 weight var1;
datalines;
1 0 0 0.8 0
1 1 0 0.8 0
1 2 0 0.8 0
1 3 0 0.8 0
1 4 0 0.8 0
1 5 0 0.8 0
1 6 0 0.8 0
1 7 0 0.8 0
1 8 0 0.8 0
1 9 0 0.8 0
1 10 0 0.8 0
1 11 0 0.8 0
1 12 0 0.8 0
1 13 0 0.8 0
2 0 0 1.1 2
2 1 1 1.1 2
2 2 . 1.1 2
3 0 0 1.01 2
3 1 0 1.01 2
3 2 1 1.01 2
3 3 . 1.01 2
4 0 1 0.98 1
4 1 . 0.98 1
4 2 . 0.98 1
4 3 . 0.98 1
4 4 . 0.98 1
5 0 0 1.13 1
6 0 0 1.05 1
6 1 0 1.05 1
6 2 0 1.05 1
6 3 0 1.05 1
6 4 0 1.05 1
6 5 1 1.05 1
6 6 . 1.05 1
6 7 . 1.05 1
6 8 . 1.05 1
7 0 0 0.89 0
7 1 0 0.89 0
7 2 0 0.89 0
7 3 0 0.89 0
7 4 0 0.89 0
7 5 0 0.89 0
7 6 0 0.89 0
7 7 0 0.89 0
7 8 1 0.89 0
7 9 . 0.89 0
7 10 . 0.89 0
8 0 0 1.1 1
8 1 0 1.1 1
8 2 0 1.1 1
8 3 . 1.1 1
8 4 . 1.1 1
;
run;
proc lifetest method=km data=have outsurv=km atrisk plots=(s) notable;
time time1*event1(0);
strata var1;
weight weight;
run;
proc sgplot data=km noautolegend;
loess x=time1 y=survival;
by var1;
xaxis values=(0 to 13 by 1);
yaxis values=(0 to 1 by 0.1);
run;
So, I have as output 3 graphics with the survival curves for each level of "var1". What I really need is one graphic that outputs all the levels of var1 curves at the same graphic.
If I use the life-table estimate method, I have what I want, but life-table (lt) does not work with weighting, so not what I need neither.
proc lifetest data=have method=lt intervals=(0 to 13 by 1) atrisk plots=(s);
time time1*event1(0);
strata var1;
run;
So any help?
In the LOESS staement, move your BY variable to a GROUP variable instead and specify the NOMARKERS option to remove the individual points. Both are listed as options in the documentation.
Note that your code generates errors in the log regarding PROC LIFETEST.
WARNING: 'ProductLimitSurvival' was compiled using a different
version of SAS.
This might result in unexpected behavior.
WARNING: Insufficient data to produce
'Stat.Lifetest.Graphics.ProductLimitSurvival' Graph.
@MFraga wrote:
No, not a homework not done because I had read before the topic you are pointing and the answer is not clear. I just need the survival smoothed curve graphic and I do not want to have the dots of my observations in the graphic.
In other topic, you said that "You can get the output from the PROC LIFETEST and then apply a LOESS statement within SGPLOT to plot the data instead of using the default SAS output".
So, following what you suggested, I coded like this (I am adding a new data because I need to stratify by some variables):
data have;
input
id time1 event1 weight var1;
datalines;
1 0 0 0.8 0
1 1 0 0.8 0
1 2 0 0.8 0
1 3 0 0.8 0
1 4 0 0.8 0
1 5 0 0.8 0
1 6 0 0.8 0
1 7 0 0.8 0
1 8 0 0.8 0
1 9 0 0.8 0
1 10 0 0.8 0
1 11 0 0.8 0
1 12 0 0.8 0
1 13 0 0.8 0
2 0 0 1.1 2
2 1 1 1.1 2
2 2 . 1.1 2
3 0 0 1.01 2
3 1 0 1.01 2
3 2 1 1.01 2
3 3 . 1.01 2
4 0 1 0.98 1
4 1 . 0.98 1
4 2 . 0.98 1
4 3 . 0.98 1
4 4 . 0.98 1
5 0 0 1.13 1
6 0 0 1.05 1
6 1 0 1.05 1
6 2 0 1.05 1
6 3 0 1.05 1
6 4 0 1.05 1
6 5 1 1.05 1
6 6 . 1.05 1
6 7 . 1.05 1
6 8 . 1.05 1
7 0 0 0.89 0
7 1 0 0.89 0
7 2 0 0.89 0
7 3 0 0.89 0
7 4 0 0.89 0
7 5 0 0.89 0
7 6 0 0.89 0
7 7 0 0.89 0
7 8 1 0.89 0
7 9 . 0.89 0
7 10 . 0.89 0
8 0 0 1.1 1
8 1 0 1.1 1
8 2 0 1.1 1
8 3 . 1.1 1
8 4 . 1.1 1
;
run;
proc lifetest method=km data=have outsurv=km atrisk plots=(s) notable;
time time1*event1(0);
strata var1;
weight weight;
run;
proc sgplot data=km noautolegend;
loess x=time1 y=survival;
by var1;xaxis values=(0 to 13 by 1);
yaxis values=(0 to 1 by 0.1);run;
So, I have as output 3 graphics with the survival curves for each level of "var1". What I really need one graphic that outputs all the levels of var1 curves at the same graphic.
If I use the a life-table estimate, I have what I want, but life-table (lt) does not work with weighting, so not what I need neither.
proc lifetest data=have method=lt intervals=(0 to 13 by 1) atrisk plots=(s);
time time1*event1(0);
strata var1;
run;
So any help?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.