BookmarkSubscribeRSS Feed
lillymaginta
Lapis Lazuli | Level 10

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 

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

lillymaginta
Lapis Lazuli | Level 10

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! 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I did, its called Interval.  Hope that is what you require?

lillymaginta
Lapis Lazuli | Level 10

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. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 4 replies
  • 723 views
  • 1 like
  • 2 in conversation