Help creating a time-varying dataset

Reply
Senior User
Posts: 1

Help creating a time-varying dataset

Hello,

 

I am new to SAS and am having trouble creating my dataset so it fits a time varying cox model and I am in desperate need for help.

My dataset looks as following;

Vx_State = a categorical variable, if 1 it stays in that state rest of the study

Vx_Date = Date when the variable changes from 0 to 1

t1 = starting time in days for that row

t2 = ending time in days for that row

 

ID       Start_date    End_date      V1_State   V1_Date       V2_State   V2_Date   V3_State   V3_Date      V4_State   V4_Date       t1  t2

1         2010-01-15  2013-12-31   0                2012-05-19  1                .                 0               2010-11-15   1              .                    1 1446

2         2010-05-13  2012-10-07   1                .                    0               .                  1               .                    0              2012-08-17  1  878

.

.

 

.

x

 

But I want to split the rows for each time a variable (Vx_State) changes by the patient ID ;

ID       Start_date    End_date      V1_State   V1_Date       V2_State   V2_Date   V3_State   V3_Date      V4_State   V4_Date     t1  t2

1         2010-01-15  2010-11-14   0               2012-05-19    1                .               0                2010-11-15 1               .                  1   303

1         2010-11-15  2012-05-18   0               2012-05-19    1                 .              1                2010-11-15 1               .                304 853

1         2012-05-19  2013-12-31   0               2012-05-19    1                 .              1                2010-11-15 1               .              854 1446   

 

I hope that my problem fairly clear, at least, and any help would be appreciated!

 

Best Regards

 

 

 

 

Grand Advisor
Posts: 16,315

Re: Help creating a time-varying dataset

I'm afraid I don't understand and I can't quite get the format of your data, it's garbled in the window. Can you post it as a data step?
Trusted Advisor
Posts: 1,114

Re: Help creating a time-varying dataset

[ Edited ]

I think I know what you mean. But your example target dataset does not quite match what I would have expected:

 

Two examples:

 

For ID 1 the start date is 2010-01-15. I take it that this is day 1 (because t1=1). Right?

Therefore, I thought 2010-11-14 should be day 304 (as calculated by %put %sysevalf('14NOV10'd-'15JAN10'd+1);). But you have t2=303 in the target dataset. Similarly, 2012-05-18 is 854 days after 2010-01-15, hence would seem to be day 855 rather than t2=853. ...

 

V3_State changes from 0 to 1 from the first to the second row of the target dataset. This is logical because of the V3_Date.

By the same logic I would have expected V1_State to switch from 0 to 1 from the second to the third row. But you left it at 0.

 

(Edit: Sorry, I'll be back tomorrow. It's getting late here in Central Europe.)

Trusted Advisor
Posts: 1,114

Re: Help creating a time-varying dataset

I think it's possible to obtain the restructured dataset within a single data step. However, it depends on the handling of special cases, as to how complicated this data step will be:

  • Vx_Date=Vy_Date (for x not equal to y)
  • Vx_Date=Start_date
  • Vx_Date=End_date

 

That said, it is possibly not even necessary to create the time-varying Vx_State variables (which I assume would be used as covariates in your Cox regression model) the way you suggested. Are you aware of PROC PHREG's capabilities for handling time-dependent covariates? (I wasn't when I was "new to SAS.") You could have a look at Example 64.6 Model Using Time-Dependent Explanatory Variables in the online doc.

 

As you can see there, PROC PHREG allows for IF-THEN statements, which make the definition of time-dependent binary indicators like your Vx_State variables fairly easy.

Post a Question
Discussion Stats
  • 3 replies
  • 511 views
  • 0 likes
  • 3 in conversation