Hello Forum Members,

I hope you can help with this conditional date finding problem. I have a database of persons that are identified by the variable "PatientID" Each patient can have "an event" that occurs on a particular date (Events A ...E in this example) . The Event is encoded as a string variable. An example of the data structure is listed below:


Code:
Patient ID    Date    EventCode
2    12/23/2013    EventB
4    9/15/2007    EventC
1    6/11/2016    EventC
3    10/3/2008    EventE
3    9/15/2002    EventC
2    4/19/2008    EventE
1    7/12/2008    EventE
3    3/22/2008    EventE
3    9/25/2012    EventE
3    5/1/2001    EventA
2    7/19/2012    EventC
4    5/7/2018    EventB
3    2/11/2003    EventE
4    11/29/2006    EventD
2    12/11/2003    EventB
3    3/1/2019    EventC
2    11/14/2019    EventB
1    2/2/2007    EventD
1    2/21/2002    EventA
1    8/15/2017    EventB
4    5/18/2014    EventA
4    10/20/2011    EventA
1    4/9/2011    EventE
1    11/27/2019    EventE
3    12/15/2004    EventE
2    9/18/2014    EventD
4    3/10/2002    EventA
3    7/27/2004    EventB
3    10/15/2015    EventC
3    2/17/2009    EventC
1    12/3/2014    EventA
1    3/19/2004    EventB
4    7/17/2018    EventB
1    2/19/2013    EventB
3    6/6/2010    EventB
3    5/4/2018    EventB
2    1/7/2012    EventE
1    10/14/2001    EventD
2    5/19/2015    EventC
2    9/4/2004    EventC
1    6/10/2019    EventC
1    11/6/2019    EventE
1    5/19/2009    EventD
4    9/25/2014    EventC
4    7/9/2005    EventC
4    3/30/2007    EventB
3    2/12/2004    EventB
4    8/31/2016    EventA
4    2/4/2008    EventD
1    3/20/2013    EventD
2    4/24/2003    EventE
2    12/3/2005    EventC
1    12/26/2006    EventE
3    6/17/2012    EventA
2    2/19/2015    EventD
1    10/18/2014    EventB
2    8/13/2012    EventE
1    8/8/2008    EventC
3    5/30/2019    EventE
4    10/31/2014    EventA
4    4/30/2005    EventB
1    5/7/2002    EventE
1    8/8/2017    EventE
3    10/15/2011    EventB
3    11/28/2001    EventB
3    3/3/2004    EventD
4    3/22/2018    EventC
I am trying to write an algorithm that for each person (patientid) it will identify the latest date occurrence for an event as long as the event is not equal to either EventD OR EventE. IN other words, find the single latest date ocurrence of either events A through C for each patient ID. I would then like this "latest date" be written as a new variable for each patientID.

I can't seem to figure out how to do this conditional greatest date math based on multiple string matches, any thoughts?

Thanks

JT