Hi Art, Sorry if I wasn't clear. This is what I am getting with the current logic I have: ID DOS EOS FLAG 1 06JUN2008:00:00:00 17JUN2008:00:00:00 1 1 17JUN2008:00:00:00 27JUN2008:00:00:00 1 2 25FEB2009:00:00:00 03MAR2009:00:00:00 3 2 04MAR2009:00:00:00 25AUG2009:00:00:00 4 3 01SEP2009:00:00:00 14SEP2009:00:00:00 5 4 11SEP2009:00:00:00 19SEP2009:00:00:00 5 This is what I need. 1 06JUN2008:00:00:00 17JUN2008:00:00:00 1 1 17JUN2008:00:00:00 27JUN2008:00:00:00 1 2 25FEB2009:00:00:00 03MAR2009:00:00:00 2 2 04MAR2009:00:00:00 25AUG2009:00:00:00 2 3 01SEP2009:00:00:00 14SEP2009:00:00:00 3 3 11SEP2009:00:00:00 19SEP2009:00:00:00 3 3 25SEP2009:00:00:00 29SEP2009:00:00:00 4 There are multiple id's with different dates. I need to flag/group them based on ID and also the service start (DOS) and end dates (EOS). If the EOS of a previous record is same as the next record of DOS in bold, I need to group them together (Bolded dates). Your logic took care of this. I am not able to figure out the flag where the EOS has ended the previous day (03Mar2009) and next service for same ID has started very next day (i.e. on 04Mar2009). I am unable to figure this out. First two dates of ID 3 are overlapping. So, I need to flag them together. flag needs to be incremental based on these conditions. When a service is neither overlapping or continuous then count it as separate flag. Please let me know if I am still not clear. Code I have so far: data want; set temp; by ID ; if first.ID and first.DOSand first.EOS then do; flag=_N_; end; retain flag ; flag=ifn(first.ID,_N_, ifn((DOS <> EOS)and DOS le lag(EOS)+1 ,flag,flag+1)); run; if I have this flag=ifn(DOS le lag(EOS)+1,flag,_N_); then the counter is skipping the numbers if they are repetitive as below. 1 1 3 3 5 6 Thanks, Jeeth.
... View more