Have you checked what "SCAN(ADDRESS,2)" returns?
Try something like
length StreetName $ 50;
StreetName = substr(Address, anyalpha(Address));
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.
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.
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →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.
Ready to level-up your skills? Choose your own adventure.