UK postcode formatting
As there are too many postcodes in the UK to make a sensible selector pick list (about 1.8 million), it is common practice to use parts of the postcode for selection and analysis. Unfortunately, the UK postcode structure does not facilitate easy splitting at a fixed number of characters. To assist with this, FastStats can prepare structured postcodes from the normal printable postcode. The FastStats postcode transformations take UK postcodes as input and can transform the postcode into one of the following formats:
- AA - Postal Area (about 124 unique entries)
- AADD - Postal Area and Postal District (about 2971 unique entries)
- AADDL - Postal Area,Postal District and London Suffix
- AADDLS - Postal Area, Postal District, London Suffix and Postal Sector (about 10,631 unique entries)
It is usual practice to split the postcode at the postcode area and district.
To apply, set UK Postcode to AADDL to be the mapping on the PostDist field.
Tip
Use Add Field to clone the postcode field and call it PostDist. Apply the mapping to the PostDist variable. In this way you have the original format postcode and the sort formatted version.
Other UK postcode transformations¶
UK Postcode to AADDL¶
This takes a standard UK postcode and produces a 5 character sort formatted post district selector. The incoming postcode must be at least 5 characters in length.
Examples:
- Cv34 4ax → cv34
- M20 2df → m 20
- Sw1a 4ww → sw 1a
This function is useful for UK postcodes because the standard format does not allow data to be sorted into the sequence users expect. The Postcode Area is the first two characters and this can be used as a Summary Code.
UK Postcode to AADD¶
This takes a standard UK postcode and produces a 4 character sort formatted post district selector. The incoming postcode must be at least 4 characters in length.
- Cv34 4ax → cv34
- M20 2df → m 20
- Sw1a 4ww → sw1a (note no space)
This format does not sort as consistently as AADDL (due to the London suffix) but is common in GIS applications.
UK Postal district to AADDL¶
This takes a first half postcode and produces a 5 character AADDL sort formatted post district selector. The incoming data must be at least 5 characters in length.
- Cv34 → cv34
- M20 → m 20
- Sw1a → sw 1a
UK Postal district to AADD¶
This takes a postcode defined up to the post district level, and produces a 4 character AADD sort formatted post district selector as used in most mapping packages. The incoming data must be at least 4 characters in length.
PostArea (UK Postcode to AA)¶
This takes a standard UK postcode and produces a two character postal area.
- Cv34 4ax → cv
- M20 2df → m
- Sw1a 4ww → sw
PostSect (UK Postcode to AADDLS)¶
This takes a standard postcode and produces a six character AADDLS sort formatted postal sector.
- Cv34 4ax → cv34 4
- M20 2df → m 20 2
- Sw1a 4ww → sw1a4
Examples
| Input Postcode | Mapping | Output (spaces shown as underscores) |
|---|---|---|
| CV34 4AL | AA | CV |
| CV34 4AL | AADD | CV34 |
| CV34 4AL | AADDL | CV34\_ |
| CV34 4AL | AADDLS | CV34\_4 |
| SW1A 7WW | AADD | SW1A |
| SW1A 7WW | AADDL | SW\_1A |
| B1 7AL | AADD | B\_\_1 |
| B1 7AL | AADDL | B\\_1\ |
| B1 7AL | AADDLS | B\_\_1\_7 |
| E1W 6AP | AADDL | E\_\_1W |