You should post data for one of the problem cases so that we can help you debug.
You can cut down your code (and data) to just what is needed to show your issue.
For example we don't need to see all of the variables you are selecting to see what your basic logic is.
Your description of the logic doesn't seem to match what the code is doing.
You said you where taking the MIN() and MAX(), but there are no MIN() or MAX() functions in the values you are selecting.
Instead you are using MIN() and MAX() in a HAVING clause. One side effect of that is that your result set could have multiple observations due to ties. So if the MAX(time) is '17:00't and there are three observations with that time then three observations will be selected.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.