In my earlier reply, I used the following 4 do-loops to search for matching records on the lower direction of each of the 4 variables. For example, matrixtable variable, is decremented by unity. It is not efficient for run-time. do matrixtable = t[m_table] to t[1] by -1 while(rc = 0); do Lo_date = Lo_date to 7305 by -1 while(rc = 0); do Lo_freq = f[m_freq] to f[1] by -1 while(rc = 0); do Lo_amount = a[m_amount] to a[1] by -1 while(rc = 0); rc = h.find(); if rc = 0 then do; rc = 1; output; end; end; end; end; end; A better way is to use: do m_table = m_table to 1 by -1 while(rc = 0); matrixtable = t[m_table]; and similarly for Lo_freq and Lo_amount. The Lo_date variable takes continous values and so needs no change. For the convenience of reading, I produce the revised program as: The two input data sets used in the program are same as in my previous reply. /** ================================================================================ **/ /** Loop Modification for efficiency **/ /**================================================================================= **/ data need; array t[3] _temporary_ (81, 85, 100); array f[4] _temporary_ (1,12,40,60); array a[6] _temporary_ (1, 1000, 5000, 10000, 100000, 1000000); format matrixtable table lo_date effectivedate lo_freq freq lo_amount amount intrate; if _n_ = 1 then do; retain max_date 19971 ; if 0 then set matrix; declare hash h(dataset:'matrix', ordered:'Y', hashexp:16); h.definekey('matrixtable','Lo_date','Lo_freq','Lo_amount'); h.definedata('intrate'); h.definedone(); end; set historytrans; do i = dim(t) to 1 by -1; if t <= table then do; m_table = i; leave; end; end; Lo_date = ifN(effectivedate > max_date, max_date, effectivedate); do i = dim(f) to 1 by -1 ; if f <= freq then do; m_freq = i; leave; end; end; do i = dim(a) to 1 by -1; if a <= amount then do; m_amount = i; leave; end; end; rc = 0; do m_table = m_table to 1 by -1 while(rc = 0); matrixtable = t[m_table]; do Lo_date = Lo_date to 7305 by -1 while(rc = 0); do m_freq = m_freq to 1 by -1 while(rc = 0); Lo_freq = f[m_freq]; do m_amount = m_amount to 1 by -1 while(rc = 0); Lo_amount = a[m_amount]; rc = h.find(); if rc = 0 then do; rc = 1; output; end; end; end; end; end; keep matrixtable table lo_date effectivedate lo_freq freq lo_amount amount intrate; run; This may not take much time to experiment with the competing program and decide. I will be too happy if OP benefits(in run-time).
... View more