data tb_1;
input bourse $ com $ time $ price $;
cards;
SH 1 20040102 3
SH 1 20040103 7
SH 2 20040102 3
SH 2 20040103 6
SZ 1 20040102 3
SZ 1 20040103 1
SZ 2 20040102 5
SZ 2 20040103 3
;
run;
data tb_2;
input bourse $ time $ prof $;
cards;
SH 20040102 5
SH 20040103 6
;
run;
data tb_3;
input bourse $ time $ prof $;
cards;
SZ 20040102 2
SZ 20040103 3
;
run;
proc sql;
create table tb_fnl as select
a.*, coalesce(b.prof,c.prof) as prof
from tb_1 as a
left join tb_2 as b on a.bourse=b.bourse and a.time=b.time
left join tb_3 as c on a.bourse=c.bourse and a.time=c.time
order by bourse,com,time;
quit;