You could easily do this with a single SQL statement (where SERIAL1 = SERIALA or SERIAL1 = SERIALB).
For a datastep merge solution, you should do a 3 table merge, being the third table a copy of dataset B. Assuming that dataset A is sorted by SerialA, it would look like this;
data BB; /* copy B to BB */
set B;
run;
proc sort; /* sort BB by SerialB */
by SerialB;
run;
data RESULT; /* do the 3 table merge */
merge A (in = a)
B (in = b rename = (SerialA=Serial1) drop = SerialB)
BB (in = bb rename = (SerialB=Serial1) drop = SerialA);
by Serial1;
if a and (b or bb); /* match by Serial1=SerialA or Serial1=SerialB */
run;
Greetings from Portugal.
Daniel Santos at
www.cgd.pt