DATA Step, Macro, Functions and more

Extracting Post Code

Reply
New Contributor
Posts: 2

Extracting Post Code

Hi all,

 

I am trying to extract the 1st letter or 2nd letter of a postcode depending on its length.

 

So if a postcode is "G72 7RT" this would be G.

 

Alternatively, a postcode of "EH12 4GY" would just be EH.

 

Any help would be much appreciated.

 

Paul

Super User
Posts: 9,890

Re: Extracting Post Code

Test for numeric, and use that for the substr:

data test;
input postcode $10.;
start = substr(postcode,1,anydigit(postcode)-1);
cards;
G72 7RT
EH12 4GY
;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 2

Re: Extracting Post Code

Posted in reply to KurtBremser

Thanks Kurt

Ask a Question
Discussion stats
  • 2 replies
  • 79 views
  • 0 likes
  • 2 in conversation