Hi everyone,
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?
Thank you!
Add spaces before and after your search term?
New_address2 = tranwrd(New_address1,' E ','EAST')
This code should work for you. Does it not?
DATA MYDATA;
New_address2 = tranwrd("123 E Eggers Street",' E ',' EAST ');
RUN;
DATA MYDATA;
New_address2 = tranwrd("123 E Eggers Avenue",' E ',' EAST ');
RUN;
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?
You need to post a larger sample data set and identify which records are being incorrectly converted.
Include the code you're using as well and the log.
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.
One way:
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
data example;
New_Address1 = "123 E Eggers Street";
New_address2 = prxchange('s/\bE\b/East/i',-1,New_address1);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.