BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tiffany1217
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
   set have(where=(date<'31DEC17'd));
   by id;
   if last.id;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
   set have(where=(date<'31DEC17'd));
   by id;
   if last.id;
run;
--
Paige Miller
novinosrin
Tourmaline | Level 20

Sir @PaigeMiller  < or <= ? /* date range is le 12/31/2017*/