I would use regexp, if I have to remove more then one thing data have; val="papaya,mango,mango,orange,papaya,fruit,veg,apple,kiwi,orange,orange,papaya,papaya"; output; run; data want (keep=processed); array removes{4} $20. ("mango","fruit","veg","orange"); length processed $2000; length tmp $200 ; /*constructing the regexp*/ if _n_=1 then do; do i=1 to dim(removes); tmp=catx('|',tmp,'(,?'||strip(removes)||')'); end; putlog tmp=; regexp=cats('s/',tmp,'//'); putlog regexp=; regexpid=prxparse(regexp); end; set have; processed=prxchange(regexpid,-1,val); processed=prxchange('s/(^,)//',-1,processed);/*removing ',' from beginning*/ putlog processed=; run;
... View more