BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
silversta
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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.

 

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

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.

 

silversta
Calcite | Level 5

My apologies, I meant to change those to 2009. Thank you for your help!

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 351 views
  • 0 likes
  • 2 in conversation