The code below compares two datasets. It merges them together and makes three datasets. One dataset contains identical observations from the two datasets. The second dataset contains observations only found in one dataset. And the third dataset contains observations only found in the other dataset.
data InBoth InOne InTwo; merge One (in=a) Two (in=b); by <variables>; if a and b then output InBoth; if a and not b then output InOne; if b and not a then output InTwo; run;