It could also be done with a RegEx but in your case may-be just use the scan() function with a blank defined as the word delimiter.
data demo;
infile datalines truncover;
input str $100.;
length cm_dementia $40;
do _i=1 to countw(str,' ');
cm_dementia=scan(str,_i,' ');
if upcase(cm_dementia) in ('DONEPEZIL', 'GALANTAMINE', 'RIVASTIGMINE', 'MEMANTINE') then
output;
end;
datalines;
donepezil galantamine donepezil/other rivastigmine memantine
;
proc print data=demo;
run;
... View more