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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

8 REPLIES 8
esjackso
Quartz | Level 8

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;

Astounding
PROC Star

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.

esjackso
Quartz | Level 8

Yeah in this case this two methods are the same.

EJ

PGStats
Opal | Level 21

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
esjackso
Quartz | Level 8

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

Astounding
PROC Star

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!


PGStats
Opal | Level 21

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
Reeza
Super User

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. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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