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
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.)
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:
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.