Replacing Mutiple Words in String in SAS
<p>I am trying to search a string for multiple words, then if any of those words are found, remove them.  I wrote the below code which seems to work on some words but not all, and when it does work, it only works on the last word in the string.</p>

<pre><code>data readyinput;
set readyforstreetname(obs=200);

array cw (48) $11 (' ave ',' avenue ',' blvd ',' boulevard ',' cir ',' circle ',' court ',' ct ',' drive ',' dr ',' e ',' east ',' highway ',' hwy ',' lane ',' ln ',' north ',' n ',' nw ',' northwest ',' parkway ',' pkwy ',' pl ',' place ',' pl ',' plaza ',' rd ',' road ',' route ',' route ',' rte ',' rte ',' rt ',' rt ',' s ',' south ',' se ',' southeast ',' st ',' street ',' suite ',' ste ',' sw ',' southwest ',' w ',' west ',' apartment ',' apt ');

do i=1 to dim(cw);

if indexw(lowcase(address_input),cw[i])
then 
do;
    add = upcase(tranwrd(lowcase(address_input),cw[i],''));
end;    
end;


drop    cw:;
run;
</code></pre>

<p>Basically what I'm trying to do is strip an address of all common words then parse out the street number and street name, which would be done in a later step.</p>