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;
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.
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;
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.
Yeah in this case this two methods are the same.
EJ
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
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
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!
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.