/*Few cells are missing in the original data, I replaced them with null values*/ data Customer; infile datalines missover; input CustomerId$ DomicileCountryCode $ IncorporationCountryCode $ ParentCustomerId $ CustomerType $; datalines; A1111 SG . X1111 BANK B2222 HK . X1111 BANK X1111 US US . . X2222 TW TW . . C3333 CN . X2222 CORP ; run; data Scorecard (where=(ScoreCardApprovedFlag='Y')); input CustomerId $ ScoreCardId CustomerCreditGrade $ ScoreCardDate ScoreCardApprovedFlag $; informat ScoreCardDate ddmmyy10.; format ScoreCardDate ddmmyy10.; cards; X1111 32104 AA+ 31/12/2016 Y X1111 32105 AAA 31/03/2017 N X1111 32103 AA 30/6/2016 Y X1111 32102 AA- 31/03/2016 Y X2222 40321 BBB 31/12/2016 N X2222 40322 BBB+ 31/12/2016 Y ; run; proc sort data = Scorecard ; by CustomerId descending ScoreCardDate ; run; proc sort data =Scorecard nodupkey; by customerid; run; /*Manually passing the values of incorporation country code, since they are not given for all the customers*/ data Scorecard; set Scorecard; if customerid= 'X1111' then IncorporationCountryCode = 'US'; if customerid= 'X2222' then IncorporationCountryCode = 'TW'; run; data customer2; set Customer; new=COALESCEc(ParentCustomerId,CustomerId); run; proc sql; create table final as select a.CustomerId, b.ScoreCardId, b.CustomerCreditGrade, a.DomicileCountryCode, b.IncorporationCountryCode from customer2 a left join Scorecard b on a.new = b.customerid order by 1; quit;
... View more