Untested without data but has a chance of to get started.
data want;
set have;
length wantstr $100; /* or long enough to hold expected longest value*/
do i= 1 to countw(HaveA,',');
if index(haveb, scan(havea,i,','))>0 then wantstr=catx(',',wantstr,scan(havea,i,','));
end;
drop i;
run;
Countw and Scan functions are told to only consider comma as delimiter for finding phrases,