hello! this is the example data I have: CUSTOMER_KEY SERVICE_KEY First_Loan_date First_Chq_date First_Service_date First_Ex_date 800001 70001 9/16/2012 10/6/2011 11/1/2012 . 800002 70002 10/18/2012 10/13/2011 11/15/2012 . 800003 70003 11/1/2012 10/22/2011 12/21/2012 . 800004 70004 11/15/2012 8/27/2012 1/27/2013 . 800005 70005 11/29/2012 11/1/2012 1/24/2014 . 800006 70006 12/13/2012 11/15/2012 6/30/2015 . 800007 70007 1/10/2013 11/29/2012 8/3/2015 . 800008 70008 1/27/2013 12/13/2012 9/30/2015 . 800009 70009 1/27/2013 12/21/2012 1/13/2016 . 800010 70010 1/27/2013 1/10/2013 4/10/2016 . 800011 70011 1/27/2013 1/10/2013 7/28/2016 . 800012 70012 1/27/2013 1/10/2013 11/27/2017 . 800013 70013 1/27/2013 1/10/2013 12/9/2017 . 800014 70014 1/27/2013 1/10/2013 12/14/2017 . 800015 70015 1/27/2013 1/10/2013 12/20/2017 . 800016 70016 1/27/2013 1/10/2013 3/22/2018 . 800017 70017 1/27/2013 1/10/2013 3/22/2018 . 800018 70018 10/6/2011 1/9/2015 . . 800019 70019 10/26/2011 1/9/2015 . . 800020 70020 11/10/2011 1/9/2015 . . 800021 70021 11/18/2011 1/9/2015 . . 800022 70022 11/25/2011 1/9/2015 . . 800023 70023 10/6/2011 . . . 800024 70024 5/12/2012 10/6/2011 . . 800025 70025 6/6/2012 2/2/2012 . . 800026 70026 10/6/2011 . 4/27/2014 2/8/2015 800027 70027 10/28/2011 . 8/7/2014 3/18/2015 800028 70028 10/31/2012 . 4/15/2015 8/1/2016 800029 70029 1/3/2013 . 5/21/2015 8/1/2016 800030 70030 4/30/2013 . 8/1/2016 8/1/2016 and from that data, I want to produce this table below: CUSTOMER_KEY SERVICE_KEY First_Service First_Loan_date First_Chq_date First_Service_date First_Ex_date 800001 70001 Chq 9/16/2012 10/6/2011 11/1/2012 . 800002 70002 Chq 10/18/2012 10/13/2011 11/15/2012 . 800003 70003 Chq 11/1/2012 10/22/2011 12/21/2012 . 800004 70004 Chq 11/15/2012 8/27/2012 1/27/2013 . 800005 70005 Chq 11/29/2012 11/1/2012 1/24/2014 . 800006 70006 Chq 12/13/2012 11/15/2012 6/30/2015 . 800007 70007 Chq 1/10/2013 11/29/2012 8/3/2015 . 800008 70008 Loan 1/27/2012 12/13/2012 9/30/2015 . 800009 70009 Loan 1/27/2012 12/21/2012 1/13/2016 . 800010 70010 Loan 1/27/2012 1/10/2013 4/10/2016 . 800011 70011 Loan 1/27/2012 1/10/2013 7/28/2016 . 800012 70012 Loan 1/27/2012 1/10/2013 11/27/2017 . 800013 70013 Loan 1/27/2012 1/10/2013 12/9/2017 . 800014 70014 Loan 1/27/2012 1/10/2013 12/14/2017 . 800015 70015 Loan 1/27/2012 1/10/2013 12/20/2017 . 800016 70016 Loan 1/27/2012 1/10/2013 3/22/2018 . 800017 70017 Loan 1/27/2012 1/10/2013 3/22/2018 . 800018 70018 Loan 10/6/2011 1/9/2015 . . 800019 70019 Loan 10/26/2011 1/9/2015 . . 800020 70020 Loan 11/10/2011 1/9/2015 . . 800021 70021 Loan 11/18/2011 1/9/2015 . . 800022 70022 Loan 11/25/2011 1/9/2015 . . 800023 70023 Loan 10/6/2011 . . . 800024 70024 Chq 5/12/2012 10/6/2011 . . 800025 70025 Chq 6/6/2012 2/2/2012 . . 800026 70026 Loan 10/6/2011 . 4/27/2014 2/8/2015 800027 70027 Loan 10/28/2011 . 8/7/2014 3/18/2015 800028 70028 Loan 10/31/2012 . 4/15/2015 8/1/2016 800029 70029 Loan 1/3/2013 . 5/21/2015 8/1/2016 800030 70030 Loan 4/30/2013 . 8/1/2016 8/1/2016 ...the column 'First_Trans' refers to the oldest date in that particular row. I have used the below case statement in proc sql, however did not give me what I wanted. ,case when lr.first_loan_date < (cr.first_chq_date and sr.first_service_date and er.first_ex_date) then 'Loan' when cr.first_chq_date < (lr.first_loan_date and sr.first_service_date and er.first_ex_date) then 'Chq' when sr.first_service_date < (lr.first_loan_date and cr.first_chq_date and er.first_ex_date) then 'Service' when er.first_ex_date < (lr.first_loan_date and sr.first_service_date and cr.first_chq_date) then 'Currency' ELSE 'None' end as First_Trans the code above is not generating what I wanted to, below is the result I get: CUSTOMER_KEY First_Trans First_Loan First_Chq_Cashed First_Service First_Currency_Exchange 80000001 Service 10/31/2008 2/4/2010 . . 80000002 Chq 10/31/2008 . . . 80000003 Currency 10/31/2008 1/2/2015 3/30/2012 . 80000004 Currency 10/31/2008 3/10/2010 4/30/2012 . 80000005 Chq 10/31/2008 . . . 80000006 Currency 10/31/2008 6/12/2014 4/15/2012 . 80000007 Chq 10/31/2008 . . . 80000008 Chq 11/1/2008 . . . 80000009 Chq 11/1/2008 . . . 80000010 Service 11/1/2008 11/19/2008 . . 80000011 Chq 11/1/2008 . . . 80000012 Chq 11/1/2008 . 8/12/2016 . 80000013 Chq 11/1/2008 . 11/23/2012 . 80000014 Chq 11/1/2008 . . . 80000015 Chq 11/1/2008 . 9/12/2013 . 80000016 Chq 11/1/2008 . 6/19/2012 . 80000017 Chq 11/1/2008 . . . 80000018 Service 11/1/2008 11/11/2008 . . in the first row, it says First_Tran is 'Service', however the First_Service data is blank or null and all rows are like that. The code is not identifying whether the referred date is lover than the rest of the dates in the same row. Thanks for helping.
... View more