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.
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.
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
The 2025 SAS Hackathon Kicks Off on June 11!
Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.