## How do I force the largest observe time to be always failure

Solved
Super Contributor
Posts: 328

# How do I force the largest observe time to be always failure

Hello, in the following data generation; I want to change the censored value for the highest observed time to be always 0 '. That is after sorting by time from minumum time to maximum, I want censored=0 for the largest time

data test;

seed=-1;

alpha1 = 2.50;

beta1 = 9.50;

do i = 1 to 100;

lambdaT = 0.025; *baseline hazard;

lambdaC= .03*light=0.15; *heavy=0.03;

er=0+sqrt(0.0001)*rannor(1);

t = rand("WEIBULL", 0.75, lambdaT);  * time of event;

c = rand("WEIBULL", 1.25, lambdaC) ;* time of censoring;

time = min(t, c);    * which came first?;

censored = (c lt t);

obs=(t lt c); * creating observation variable from censored when

y= alpha1 + beta1*t + er;

output;

end;

run;

Accepted Solutions
Solution
‎07-15-2013 12:35 PM
Super User
Posts: 6,785

## Re: How do I force the largest observe time to be always failure

I think the intent is simpler than that.  The way I read it, the IF/THEN statement should be:

if _n_=1 then censored=0;

All of the other work is necessary ... sorting, then reading the data back into a DATA step.  There is no easy way to make all of this happen in a single DATA step.

All Replies
Super Contributor
Posts: 334

## Re: How do I force the largest observe time to be always failure

Posted in reply to desireatem

Is this what you need?

Proc sort data=test out=test2; by descending time; run;

data test3;

set test2;

by descending time;

if first.time then censored = 0;

run;

Solution
‎07-15-2013 12:35 PM
Super User
Posts: 6,785

## Re: How do I force the largest observe time to be always failure

I think the intent is simpler than that.  The way I read it, the IF/THEN statement should be:

if _n_=1 then censored=0;

All of the other work is necessary ... sorting, then reading the data back into a DATA step.  There is no easy way to make all of this happen in a single DATA step.

Super Contributor
Posts: 334

## Re: How do I force the largest observe time to be always failure

Posted in reply to Astounding

Yeah in this case this two methods are the same.

EJ

Posts: 5,539

## Re: How do I force the largest observe time to be always failure

Posted in reply to desireatem

You can do it this way:

proc sql;

create table testMax as select max(t) as maxt from test;

update test

set censored = 0

where t = (select maxt from testMax);

drop table testMax;

quit;

PG

PG
Super Contributor
Posts: 334

## Re: How do I force the largest observe time to be always failure

I like this method (one correction I believe it not just t but min of t or c that makes up time) .. .you could probably select the obs of the max time into a macro variable and use that in the update where and avoid create the temp table all together.

EJ

Super User
Posts: 6,785

## Re: How do I force the largest observe time to be always failure

PG,

I suspect you're fine with that ... Not knowing anything about a Weibull distribution, I wasn't sure if a tie would be possible.  I didn't want to allow the possibility of uncensoring two observations.  That's probably impossible, given the use of RAND, but I was too lazy to look it up when I had a working approach!

Posts: 5,539

## Re: How do I force the largest observe time to be always failure

Posted in reply to Astounding

Well, OP's request wasn't that clear to me. The Weibull distribution is continuous, so that ties are very unlikely.  I'm waiting for some feedback from OP.

PG
Super User
Posts: 23,771

## Re: How do I force the largest observe time to be always failure

Posted in reply to desireatem

You probably don't need to be generating a censoring time then do you? About half the lines in your original code could be deleted.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 8 replies
• 362 views
• 6 likes
• 5 in conversation