So if B has 581 observations and 34 do not match any ids from A that leaves 547 that do match. The count of 551 matched records means that four extra observations were added by merging with A. So either one id in B matched to 5 observations in A or some other combination. To find which ids are appearing in multiple times you can use the FIRST. and LAST. variables that the BY statement will generate.
data check;
merge alldata (in=in1) pubdata3 (in=in2);
by course;
if in1 and in2 and not (first.course and last.course);
run;
proc print;
run;