Hello, how do I return the second to the last observation when a condition is not met? I am using the last function to return observations that are within a certain date range. When the observation is not in a particular date range I want the record before it to be returned.
Here' an example. I want the last.id to be returned if the date range is le 12/31/2017 when this condition is not met i want it to return the 2nd to the last record for each id
ID DATE
1 12/1/2016
1 11/3/2017
1 12/8/2019
2 12/1/2017
2 12/30/2017
3 12/1/2017
so ideally these records would be returned
ID DATE
1 11/3/2017
2 12/30/2017
3 12/1/2017