yugao1986 发表于 2011-8-19 19:30 
Here are a couple of ways to do it.
data a;
input id $ x1 x2 x3;
cards;
1 8 20 3
3 3 0 8
4 2 4 0
;
data b;
input id $ x1 x2 x3;
datalines;
1 0 7 3
4 9 0 5
5 8 5 9
;
data want(drop=x11 x22 x33);
merge a b(rename=(x1=x11 x2=x22 x3=x33));
by id;
x1=sum(x1,x11);x2=sum(x2,x22);x3=sum(x3,x33);
run;
proc print;run;
proc sql;
select coalesce(a.id,b.id) ,sum(a.x1,b.x1) as x1 ,sum(a.x2,b.x2) as x2,sum(a.x3,b.x3) as x3
from a
full join b on a.id=b.id
order by 1
;
quit;