Hello all,
I have data that is structured as below for example. I want to create the injury indicator based on the interval_start and interval_end dates. The indicator should be 0 until the first injury is experienced within the interval dates, at which point it should be 1. The indicator will remain 1 for those without a second injury and needs to change to 2 once the second injury occurs within the interval dates and remain 2 for the rest of the records with that id.
id injury_date1 Injury_date2 interval_start interval_end injury_indicator
1 7/14/2008 . 5/1/2008 5/31/2008 0
1 7/14/2008 . 6/1/2008 6/30/2008 0
1 7/14/2008 . 7/1/2008 7/31/2008 1
1 7/14/2008 . 8/1/2008 8/31/2008 1
1 7/14/2008 . 9/1/2008 9/30/2008 1
1 7/14/2008 . 10/1/2008 10/31/2008 1
2 6/6/2009 10/20/2009 4/1/2009 4/30/2008 0
2 6/6/2009 10/20/2009 5/1/2008 5/31/2008 0
2 6/6/2009 10/20/2009 6/1/2008 6/30/2008 1
2 6/6/2009 10/20/2009 7/1/2008 7/31/2008 1
2 6/6/2009 10/20/2009 8/1/2008 8/31/2008 1
2 6/6/2009 10/20/2009 9/1/2008 8/30/2008 1
2 6/6/2009 10/20/2009 10/1/2008 10/31/2008 2
2 6/6/2009 10/20/2009 11/1/2008 11/30/2008 2
2 6/6/2009 10/20/2009 12/1/2008 12/31/2008 2
2 6/6/2009 10/20/2009 1/1/2008 1/31/2008 2
I have tried to accomplish this through a series of data steps with no success. Any help provided would be most appreciated!
This should work:
data WANT;
set HAVE ;
by ID;
if first. ID then INJURY_INDICATOR=0;
if INTERVAL_START <= INJURY_DATE1 <= INTERVAL_END
| INTERVAL_START <= INJURY_DATE2 <= INTERVAL_END then INJURY_INDICATOR+1;
run;
Please check the examples you provide. You seem to have mixed 2008 and 2009. Spend more time checking to save our time.
This should work:
data WANT;
set HAVE ;
by ID;
if first. ID then INJURY_INDICATOR=0;
if INTERVAL_START <= INJURY_DATE1 <= INTERVAL_END
| INTERVAL_START <= INJURY_DATE2 <= INTERVAL_END then INJURY_INDICATOR+1;
run;
Please check the examples you provide. You seem to have mixed 2008 and 2009. Spend more time checking to save our time.
My apologies, I meant to change those to 2009. Thank you for your help!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.