# SAS and R still give median survival time although more than half of the data are censored?

#### tduong79

##### New Member
Hi, I was fitting some Kaplan Meier plots for the survival analysis for the data set below.

Because there are only two out of five events happening, why are SAS and R still able to give the median survival time, which is 5.9539 (in moths)?

Here are my codes in R:
pfs_fit <- survfit(Surv(pfs_m, pfs_stat) ~ 1, data = data)
os_fit <- survfit(Surv(os_m, os_stat) ~ 1, data = data)

#### hlsmith

##### Less is more. Stay pure. Stay poor.
I haven't done this much in R, but more experienced in SAS. Can you post the SAS code. I know it is a little tricky to get the code right the first time. censor(0)

Also, look at the plots to make sure they make sense and you don't have event and censored switched.

#### tduong79

##### New Member
I haven't done this much in R, but more experienced in SAS. Can you post the SAS code. I know it is a little tricky to get the code right the first time. censor(0)

Also, look at the plots to make sure they make sense and you don't have event and censored switched.
Hi, this is my SAS code. I got the same results as R though.

proc lifetest data=data confband=all outsurv=t;
time pfs_m*pfs_stat(0);
/*time os_m*os_stat(0);*/
run;

#### Miner

##### TS Contributor
Because the survival analysis takes the time of the censored data into account in the calculation. I'm not an R or SAS user, so I don't know which approach they use, but the least squares approach places more weight on the deaths, while the maximum likelihood approach places relatively more weight on the censored times.

#### hlsmith

##### Less is more. Stay pure. Stay poor.
Yup, when I ran it I got a median survival, see below code:

Code:
data data;
input pfs_stat pfs_m Died;
datalines;
0 13.45 0
1 5.95 1
0 2.70 0
1 4.74 1
0 5.66 0
;

run;

ODS GRAPHICS ON;
proc lifetest data=data
PLOT = survival(ATRISK = 0 TO 20 BY 1 cb);
time pfs_m*Died(0);
run;
ODS GRAPHICS OFF;
I am guessing it has to do with the censoring and event happening w/in the same integer (5), when I changed the times to integers it did not provide a median survival.

#### tduong79

##### New Member
Because the survival analysis takes the time of the censored data into account in the calculation. I'm not an R or SAS user, so I don't know which approach they use, but the least squares approach places more weight on the deaths, while the maximum likelihood approach places relatively more weight on the censored times.
Thank you. I just read the documentation. The survfit() function in R and Proc lifetest in SAS indeed use the maximum likelihood approach.
As @hlsmith mentioned, it is great if you can elaborate a little bit.

#### Miner

##### TS Contributor
See the Dealing with Suspensions (censoring) section of Maximum Likelihood Estimation. While this article talks in terms of product reliability, survival analysis uses the same methods and formulas. Both are events in time.