data _null_;
x='Hillcrest Avenue Hillcrest Auckland ';
y=prxchange('s/\w+\s+\w+$//',1,strip(x));
put x= y=;
run;
In practice, you might want to check that you have more than 2 words in the address, before doing this:
address = substr(address, 1, length(address) - 2 - length(scan(address, -1)) - length(scan(address, -2)));
data _null_;
x='Hillcrest Avenue Hillcrest Auckland ';
call scan(x, -2, position, length);
substr(x,position)=' ';
put x=;
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 16. Read more here about why you should contribute and what is in it for you!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.