BookmarkSubscribeRSS Feed
taylormccormick
Calcite | Level 5
I'm trying to create a function that pulls the street name (whether one or two or three words) out of an address...to get it to pull in anything following the street number...and i'm stuck...
 
DATA work.practice;
Address = '44 Bird Street';
StreetName = SUBSTR(SCAN(ADDRESS,2), ANYSPACE(ADDRESS)));
RUN;
 
This doesn't work at all...don't know where to go with it.  Thanks!
3 REPLIES 3
andreas_lds
Jade | Level 19

Have you checked what "SCAN(ADDRESS,2)" returns?

Spoiler
it returns only "Bird"

Try something like

length StreetName $ 50;
StreetName = substr(Address, anyalpha(Address));
ballardw
Super User

If you have many addresses I promise that no single code will work for all of them.

 

One of my datasets I was supposed to geocode had an "address" field that users entered information other than the address because that appeared at the top of screens or print outs. So I had to clean out stuff like:

 

Address= "See the woman in the back apartment  4433 Some actual Street".

Or rural addresses like "Intersection Baseline Road and County Rd 33".

 

Good luck and have fun.

s_lassen
Meteorite | Level 14

One possibility is to use Pearl regular expressions. E.g.:

data test;
  Address = '44 Bird Street';
  PrxID=PrxParse('/\d+\s+(.*)/');
  if PrxMatch(PrxID,Address) then
    StreetName=PrxPosN(PrxID,1,Address);
run;

This function just finds one or more digits ("\d+"), followed by one or more blanks ("\s+"), and puts the rest of the string into a capture buffer ("(.*)"), the contents of which is returned by the PrxPosN function.

You will probably find that more sophistication is needed (which is why I suggest that you get into PRX functions), but this is a start.

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1582 views
  • 0 likes
  • 4 in conversation