Hi,
That is the reason for me trying to create date range variables "max_before_valid_dttm" & "min_after_valid_dttm" for each record based on its pre-match and post-match valid_dttm values, we will consider the min value of them as final_dttm.
Apart from that, the code provided now is not as expected and causing some wrong cust_sk and date assignments.
The code given yesterday was perfectly working on subset data. But failing due to HASH memory issue in SAS when run on full table.
If we can resolve that, it will be absolutely fine.
Working SAS Code with HASH object program:
data one; infile datalines; input CURR_RK ORIG_RK CUST_SK VALID_DTTM: anydtdte10. ; format VALID_DTTM date9.; datalines; 41 2673 2342321 1-Sep-12 41 41 12559928 1-Jan-13 41 4615581 14452649 1-Feb-13 41 4615581 67316104 1-Aug-14 41 41 72971041 1-Oct-14 41 4615581 74341618 1-Nov-14 41 8828883 63829111 1-Jul-15 9217 9217 21128775 1-Jan-13 9217 10124544 15142897 1-Jan-13 9217 9217 30874351 1-Mar-13 9217 9217 71276102 1-Sep-14 9217 10124544 74885982 1-Nov-14 346372 346372 6478392 1-Sep-14 7801669 6368875 2591876 1-Dec-12 7801669 7801669 3829995 1-Jan-13 7801669 7801669 97082679 1-Aug-15 7801669 6368875 106930088 1-Oct-15 7801669 7801669 107207912 1-Nov-15 ; run; data one; set one; by curr_rk; if first.curr_rk then n=0; n+1; run; data want; if _n_=1 then do; if 0 then set one(rename=(CUST_SK=new_sk VALID_DTTM=new_dt)); declare hash h1(dataset:'one(rename=(CUST_SK=new_sk VALID_DTTM=new_dt) where=(CURR_RK=ORIG_RK))'); h1.definekey('CURR_RK','ORIG_RK'); h1.definedata('new_sk','new_dt'); h1.definedone(); if 0 then set one(keep=ORIG_RK rename=(ORIG_RK=_ORIG_RK)); declare hash h2(dataset:'one(rename=(ORIG_RK=_ORIG_RK CUST_SK=new_sk VALID_DTTM=new_dt))'); h2.definekey('CURR_RK','n'); h2.definedata('new_sk','new_dt','_ORIG_RK'); h2.definedone(); end; set one; by curr_rk; if first.curr_rk then do; if curr_rk = orig_rk then do;new_sk=CUST_SK; new_dt=VALID_DTTM;end; else do;call missing(new_sk,new_dt);rc=h1.find(key:CURR_RK,key:CURR_RK);end; end; else do; if curr_rk = orig_rk then do;new_sk=CUST_SK; new_dt=VALID_DTTM;end; else do; do k=n-1 to 1 by -1; call missing(new_sk,new_dt); rc=h2.find(key:CURR_RK,key:k); if CURR_RK=_ORIG_RK then leave; end; end; end; drop rc k n _ORIG_RK; run;
... View more