04-21-2017 02:46 PM
I'm working on an address data set I have several addresses that have a "E" in place of "East" for example:
Instead of "123 E Eggers Street" I want 123 "East Eggers Street"
But when i use
New_address2 = tranwrd(New_address1,'E','EAST')
Every E is replaced with EAST. Is there anyway around this?
04-21-2017 03:17 PM
04-21-2017 03:25 PM
New_address2 = tranwrd("123 E Eggers Avenue",' E ',' EAST ');
Produces "123 EAST Eggers Avenue", which I think is what you had hoped for (?) Was there an example that you tried using this process and printed EAST unexpectedly?
04-21-2017 03:37 PM
The Tranwrd function is working as designed: (from online help) Replaces all occurrences of a substring in a character string.
You might look into FINDW to find the E as a word and then use other functions to insert the text.
data example; New_Address1 = "123 E Eggers Street"; pos=findw(New_address1,'E'); if pos>0 then New_address2 = catx(' ',substr(New_address1,1,Pos-1),"East",substr(New_address1,Pos+1)); run;
Note that will only change the first E