BookmarkSubscribeRSS Feed
eemrun
Obsidian | Level 7
I have addresses that I need to separate as street address. The last two words in the address field is usually the region and city. Any ideas?

Before
Hillcrest Avenue Hillcrest Auckland

After
Hillcrest Avenue
3 REPLIES 3
Ksharp
Super User

data _null_;
x='Hillcrest Avenue Hillcrest Auckland   ';
y=prxchange('s/\w+\s+\w+$//',1,strip(x));
put x= y=;
run;
Astounding
PROC Star

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)));

novinosrin
Tourmaline | Level 20
data _null_;
x='Hillcrest Avenue Hillcrest Auckland   ';
call scan(x, -2, position, length);
substr(x,position)=' ';
put x=;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 3 replies
  • 736 views
  • 3 likes
  • 4 in conversation