I have the following data
id rx_start rx_end event event_date
1 1/1/2005 3/1/2005 1 2/1/2005
2 2/2/2005 4/3/2006 1 7/5/2005
3 4/4/2005 5/5/2005 0
data have;
informat rx_start rx_end event_date mmddyy10.;
format rx_start rx_end event_date date9.;
input id rx_start rx_end event event_date;
cards;
1 1/1/2005 3/1/2005 1 2/1/2005
2 2/2/2005 4/3/2006 1 7/5/2005
3 4/4/2005 5/5/2005 0;
Run;
I want to create cumulative exposure intervals as the following
interval 1 ) time between rx_start and rx_end <30 days then interval=1 and event1=1 (code the event as 1 if occurred within this interval)
2) 1 month- 3months
3) 3-6 months
4) > 6 months
The same id can have multiple intervals and the event should be assigned to the interval where it happens
for example for id 2:
id interval start_date end_date event1
2 1 2/2/2005 03/03/2005 0
2 2 03/03/2005 05/02/2005 0
2 3 05/02/2005 07/31/2005 1
I want to fit this as a cox model
Please post test data in the form of a datastep!! we are not here to type test data in or guess what structure you have.
Should be pretty easy to do something like (not tested as not typing test data in!):
data want (keep=id interval_:); set have; interval=1; interval_start_date=rx_start; interval_end_date=intnx('days',rx_start,30); event1=ifn(interval_start_date <= event_date <= interval_end_date,1,0); output; interval=2; interval_start_date=intnx('months',rx_start,3); interval_end_date=intnx('months',rx_start,6); event1=ifn(interval_start_date <= event_date <= interval_end_date,1,0); output; interval=3; interval_start_date=intnx('months',rx_start,6); interval_end_date=intnx('months',rx_start,12); /* Not sure what upper limit is? */ event1=ifn(interval_start_date <= event_date <= interval_end_date,1,0); output; run;
Thank you RW9 and apologize for not posting in a datastep format. Would it be possible to add a column to the code that indicates the interval (e.g. 1,2,3).
Thanks!
I did, its called Interval. Hope that is what you require?
Thank you for the prompt reply. The code generates the interval_start_date and interval_end_Date only but I need the additional variable that indicates the interval category to use it in the regession.
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.