Hi! I have the following dataset Data have; input id $ dt:yymmdd10. year test $ result $; format dt date11.; datalines; ABCDE 20100429 2010 T1 N ABCDE 20100712 2010 T1 N ABCDE 20101025 2010 T1 Y ABCDE 20110509 2011 T1 Y ABCDE 20110909 2011 T1 Y ABCUK 20150301 2015 T2 Y ABCUK 20150801 2015 T1 N ABCUK 20150914 2015 T1 N ABCGH 20190613 2019 T1 N ABCGH 20190815 2019 T2 N ABCPK 20130409 2013 T1 N ABCPK 20131021 2013 T1 N ; I want to select the record with the latest date in a year for all records with same id and year. I also want if a record that has a result ‘Y’ but not the latest date, it should be prioritised and selected over other records with result ‘N’, same ID and date in later months. In summary, my objective is to have only one record (from same IDs) in a year, if the result variable is ‘Y’ or ‘N’ for all, I want the record with the latest date. Any record (with same ID) with result ‘Y’ in an earlier date should be selected over a record with result ‘N’ in a later date. The output should have only one record for each ID in each year. See below: Want id dt Year test result ABCDE 20101025 2010 T1 Y ABCDE 20110909 2011 T1 Y ABCUK 20150301 2015 T2 Y ABCGH 20190815 2019 T2 ABCPK 20131021 2013 T1 I have tried Price sql; Create table want as Select* From have Group by id Having dt=max(dt); Quit; But it does not give the output based on my specific requirements. Thank you for your help!
... View more