Hi SuppersReady,
Based on the work presented in SUGI paper 232-31, "Crafting your own index" (http://www2.sas.com/proceedings/sugi31/232-31.pdf), the following approach may work:
/*Let's create some dummy data:*/
/*1. Postcode changes */
data pc_chgs;
input dt_chg date7. pc $ pc_new $;
format dt_chg date.;
cards;
01Jan08 A11AA A11AB
01Jan08 B11AA B11AB
01Jan09 A11AB A11AC
;
run;
/*2. Customer addresses */
data cust;
input nm $ dt_reg date7. pc $;
format dt_reg date.;
cards;
Smith 01Aug07 A11AA
Jones 01Aug08 A11AB
Brown 01Aug08 A11AA
Dixon 01Aug08 B11AA
;
run;
/* Now we index the postcode change file on old post code */
proc sql;
create index pc on pc_chgs(pc);
quit;
/* Now the tricksy bit */
/* Use a data step with two input data sets: cust and pc_chgs */
/* The key= option to specify that pc_chgs is a lookup table */
/* Uncomment "and dt_reg lt dt_chg", below, if postcodes are re-used */
data cust_chgs(keep=nm dt_reg dt_chg pc_old pc_new);
set cust (rename = (pc = _pc));
length pc $8.;
if _pc = lag(_pc) then do;
pc = 'ZZZ';
link fetch;
_error_ = 0;
end;
pc = _pc;
do _iorc_ = 0 by 0
until ( _iorc_ ne 0);
link fetch;
if _iorc_ eq 0 /* and dt_reg lt dt_chg */ then do;
pc_old = pc;
pc = pc_new;
output;
end;
else _error_ = 0;
end;
return;
fetch: set pc_chgs
key=pc
;
run;
This should give you three or six records, depending on whether you allow postcodes to be recycled.
If you haven't looked through the SUGI (now SGF) papers they are available here:
http://support.sas.com/events/sasglobalforum/previous/online.html
I hope this helps, let me know if you have any questions, not covered by the SUGI paper.
ProcMe