BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9


data kaplan;

input time survival1;

cards;

4 .6

5 .55

6 .3

7 .1

9  0

;

run;

proc iml;

use kaplan;

read all  var{TIME SURVIVAL1} into DM;

close;

SURVIVAL1 = DM[,2]; TIME = DM[,1];

n = nrow(DM);

   

segment = J(nrow(DM),1,1); *print segment;

SS=J(nrow(survival1),1,1);

do i = 1 to n ;

if 1=n then SS=0;

else if  i< n-1 then SS=SURVIVAL1-SURVIVAL1[i+1];

end;

TT=J(nrow(time),1,1);

do i = 1 to n;

if 1=n then TT=0;                    

else if i < n-1  then TT=time[i+1]-time;

end;

create kaplann var{time  survival1 SS TT };

append;

quit;

data kaplan_sum;

set kaplann;

sur_time=SS*TT;

drop time  survival1;

run;

proc print data=kaplan_sum;

run;



This output is wrong, there is supposed to be just 4 observations. The 4th and fifth observation for SS is wrong.


SS= (.6-.55)+(.55-.3)+(.3-.1)+(.1-0)

TT= (5-4)+(6-5)+((7-6)+(9-7))

This is wrong.

i   SS  TT  TT*SS

10.0510.05
20.2510.25
30.2010.20
41.0011.00
51.0011.00

This is how the correct output is supposed to look like;

SS= (.6-.55)+(.55-.3)+(.3-.1)+(.1-0)

TT= (5-4)+(6-5)+((7-6)+(9-7))

  

i    SS   TT       SS*TT

1

0.05

1

        0.05

2

0.25

1

       0.25

3

0.20

1

       0.20

4

0.1

2

       0.2

1 ACCEPTED SOLUTION

Accepted Solutions
desireatem
Pyrite | Level 9

proc iml;

use kaplan;

read all  var{TIME SURVIVAL1} into DM;

close;

SURVIVAL1 = DM[,2]; TIME = DM[,1];

n = nrow(DM);

  

segment = J(nrow(DM),1,1); *print segment;

SS=J(nrow(survival1),1,1);

do i = 1 to n ;

if i=n then SS=0;

else if  i< n-1 then SS=SURVIVAL1-SURVIVAL1[i+1];

end;

TT=J(nrow(time),1,1);

do i = 1 to n;

if i=n then TT=0;                   

else if i < n-1  then TT=time[i+1]-time;

end;

create kaplann var{time  survival1 SS TT };

append;

quit;

data kaplan_sum;

set kaplann;

sur_time=SS*TT;

drop time  survival1;

run;

proc print data=kaplan_sum;

run;

View solution in original post

2 REPLIES 2
desireatem
Pyrite | Level 9

ANSWER

desireatem
Pyrite | Level 9

proc iml;

use kaplan;

read all  var{TIME SURVIVAL1} into DM;

close;

SURVIVAL1 = DM[,2]; TIME = DM[,1];

n = nrow(DM);

  

segment = J(nrow(DM),1,1); *print segment;

SS=J(nrow(survival1),1,1);

do i = 1 to n ;

if i=n then SS=0;

else if  i< n-1 then SS=SURVIVAL1-SURVIVAL1[i+1];

end;

TT=J(nrow(time),1,1);

do i = 1 to n;

if i=n then TT=0;                   

else if i < n-1  then TT=time[i+1]-time;

end;

create kaplann var{time  survival1 SS TT };

append;

quit;

data kaplan_sum;

set kaplann;

sur_time=SS*TT;

drop time  survival1;

run;

proc print data=kaplan_sum;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 748 views
  • 0 likes
  • 1 in conversation