BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Peter_C
Rhodochrosite | Level 12
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

hackathon24-white-horiz.png

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.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 2568 views
  • 0 likes
  • 3 in conversation