There's a typo in your postal code list...
but this is what you can do using proc sql
[pre]
data have1;
input id postal $;
cards;
1 K0A3K0
2 K0A8PN
3 K0A3N0
4 K0A8T6
;
run;
data have2;
input postal $ weight;
cards;
K0A 1
K0A3K0 0.69
K0A3N0 0.74
;
run;
proc sql;
create table want as
select h1.id, h1.postal, h2.weight as weight1, h2_s.weight as weight2, case when h2.weight=. then h2_s.weight else h2.weight end as weight
from have1 as h1
left join have2 as h2
on h1.postal=h2.postal
left join have2 as h2_s
on substr(compress(h1.postal), 1,3)=compress(h2_s.postal)
order by id;
quit;
[/pre]
... View more