Below some tested code based on Ksharp's and Art's suggestions. What it does: 1 Data step 'SearchReplacePattern' to build a list of patterns based on target words. Eg. if the target word is UUNET then the data step will create a pattern which will match any combination of this string as defined. For UUNET the Regular Expression would be: \bU *U *N *E *T\b 2. Data step 'have' to create some sample data 3. Data step 'want' compiles in the first iteration all patterns as needed for prxchange(). Then loops for every iteration of the data step through all compiled RegEx using prxchange() to replace all matching patterns with the desired target value. data SearchReplacePattern(keep=_SearchReplacePattern);; length TargetWord $40 _SearchReplacePattern $160.; do TargetWord = 'UUNET','ABC' ; _SearchReplacePattern=prxchange('s/(\S{1}\B)/$1 */i',-1,strip(TargetWord)); _SearchReplacePattern=cats('s/\b',_SearchReplacePattern,'\b/',TargetWord,'/i'); put _SearchReplacePattern=; output; end; run; data have; length String $ 40; String='word1 word2 uU net wordN'; output; String='ab c word2 ab cword3 u u Net word a b c'; output; run; data want(drop=_:); set have; if _n_=1 then do; do _i=1 to last; set SearchReplacePattern nobs=last point=_i ; _PatternID=prxparse(_SearchReplacePattern); end; end; put 'Before: ' @9 String ; do _PatternID=1 to last; String=prxchange(_PatternID,-1,String); end; put 'After: ' @9 String /; run;
... View more