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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1901 views
  • 0 likes
  • 3 in conversation