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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.