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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 661 views
  • 0 likes
  • 2 in conversation