data AB AC AD;
merge A(in=x) B(in=y) C(in=z);
by name;
if x and y then output AB;
if x and z then output AC;
if x and not y and not z then output AD;
run;
data AB AC AD;
merge A(in=x) B(in=y) C(in=z);
by name;
if x and y then output AB;
if x and z then output AC;
if x and not y and not z then output AD;
run;