Hi, I'm new to the forum, so I'm looking forward to not only getting some support from the community forums but also hoping to also provide some where possible. I can't seem to figure out the following (without considering transposing the data in some way). I'm trying to do some calculations using dates but the dates I'm working with are on two separate records for the same individual. I suspect there is some lag function, but this is an area that I am unfamiliar with. Here is what the data looks like: ID DATE1 DATE2 1 2009-06-14 2009-08-11 1 2009-10-29 1 200912-31 2 2009-09-05 2009-11-10 2 2009-10-09 2 2010-05-23 and so on..... The output I'm looking for is the following: ID DATE1 DATE2 DAYS 1 2009-06-14 2009-08-11 79 1 2009-10-29 1 2009-12-31 2 2009-09-05 2009-11-10 194 2 2009-10-09 2 2010-05-23 and so on..... So, for the first person (ID #1) (LAG)DATE1 - DATE2 = 20091029 - 20090811 = 79 days. So, no further calculations are required. For the 2nd person (ID #2) (LAG)DATE1 - DATE2 = 20091009 - 20091110 = -32 days. When a negative "DAYS" is encountered, I would like to be able to check the next record for that person to see if there is a non-negative count. So, it would loop to the 3rd record whereby (LAG)DATE1 - DATE2 = 20100523 - 20091110 = 194 days. For illustrative purposes, I've included the actual dates, but I did convert the dates into numeric values using NEWDATE1 = input (DATE1, yymmdd8.) to allow for the calculations. Essentially, I would like one record per person which tells me when did the next event (DATE1) occur after DATE2. Any help with this would be GREATLY appreciated. Thanks in advance for your time, M. Anthony
... View more