I work for a non-profit company that monitors homeless shelters activity. I was given the task to define “Episode” at client grouping by their shelter stays. I’m not sure how to proceed because problem requires a lot more knowledge about functions than I currently know. So any assistance or advice will would be helpful.

An Episode is where a client can visit multiple shelters as long as the duration between shelter visits is less than 33 days. If a client exits and reentries a shelter where the duration is greater than 33 days between the two visit then that visit is classified as a new episode.
I apologize if logic doesn’t seem so direct.
Example of my query data is listed below. Again column field I need help defining is “Episode”.

Example of result: Client # 68966 made 12 shelter visits. Client has two episodes during the 12 visits. Episode 1 is stopped at exit date of 3/16/10 because client reentered shelter on 7/12/2010. Duration between shelter exit (3/16/10) to shelter reentry (7/12/2010) was 118 days.

Client Provider EntryDate ExitDate PreviousEntryDate Duration between Visits Episode 68966 VOAGO 5/15/2009 6/22/2009 6/22/2009 0 1 68966 6th 6/22/2009 7/29/2009 7/29/2009 0 1 68966 FOH 7/29/2009 12/15/2009 12/19/2009 4 1 68966 6th 12/19/2009 1/2/2010 1/3/2010 1 1 68966 8th 1/3/2010 1/15/2010 1/18/2010 3 1 68966 FOH 1/18/2010 3/16/2010 7/12/2010 118 1 68966 8th 7/12/2010 7/26/010 8/19/2010 24 2 68966 VOAGO 8/19/2010 11/7/2010 12/6/2010 29 2 68966


6th 12/6/2010 2/16/2010 2/16/2010 0 2 68966 VOAGO 2/16/2010 3/13/2010 3/13/2010 0 2 68966 6th 3/13/2010 5/10/2010 5/10/2010 0 2 68966
VOAGO 5/10/2010 6/2/2010 2 10600 VOAGO 8/19/2010 11/7/2010 12/6/2010 0 1 10600 6th 12/6/2010 2/16/2010 2/16/2010 0 1 10600 VOAGO 2/16/2010 3/13/2010 5/10/2010 58 1 10600 6th 5/10/2010 6/2/2010 0 2