Desktop productivity for business analysts and programmers

Extracting a postcode from an address

Reply
N/A
Posts: 0

Extracting a postcode from an address

As the heading suggests I am trying to create another column containing just the postcode. I am new to SAS and am really struggling. After reading various threads I think i need to use the SUBSTR function but keep ending up with a blank column.
The only thing I have managed to do is REVERSE the line so the postcode is at the start.

Any help greatfully appreciated.
Super Contributor
Super Contributor
Posts: 3,174

Re: Extracting a postcode from an address

What is the exact format of your INPUT-side and OUTPUT-side (desired) data string?

Consider that the SAS FIND function does permit searching from the end of a character variable, when using a negative third-argument, which is somewhat easier than having to go through the REVERSE gyrations multiple times.

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 2,177

Re: Extracting a postcode from an address

google for postcode and perl regular expression
That should help you locate a postcode within an address, if it is present.

Alternatively, if you can assume postcode is the last one or two words, try
length postcode $11 ;
postcode= scan( address, -1) ;
if length( postcode ) < 5 then
postcode= scan( address, -2) !!' '!! scan( address, -1) ; Message was edited by: Peter.C
Ask a Question
Discussion stats
  • 2 replies
  • 376 views
  • 0 likes
  • 3 in conversation