05-16-2018 09:56 AM
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.
05-16-2018 09:59 AM
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;