Using patterns to categorise postcodes in to postal area
In last months worksheet we applied a pattern to validate or transform a quantity response during an interview. We will now look at applying a pattern at analysis stage. This particular example uses a derived variable in conjunction with a pattern to extract the postal area part from a full UK postcode.
This example is drawn from the Snap WebHost edition of the snCrocodile survey which is preloaded on the Snap 9 Installation CD.
In this example, we will use a literal response, open ended question. This question has a source pattern of ‘Postcode UK’ applied. This pattern is pre-loaded within Snap and may be used to validate replies to literal response questions representing UK postcodes.
The UK postcode standard is made up of four components; Area, District, Sector and Unit. Each component is then broken down to accept a particular literal response as detailed in the table below:
| Component | Acceptable Literal Response | Example |
|---|---|---|
| Area | {letter} {letter}{letter} |
B12 4LT BS35 3UW |
| District | {digit} {digit}{digit} {digit}{letter} |
BA3 4HT BS35 3UW SW1Y 4RF |
| Sector | {digit} | BS35 3UW |
| Unit | {letter}{letter} | BS35 3UW |
Step by step

Step 1
The first step is to create a new pattern that will extract postcode area from a full UK postcode.
1. Select Tailor | Variables from the main snap toolbar.

2. Click
from the Variable Tailoring window.
3. Highlight the ‘Postcode UK’ pattern and use the
button to make a copy of it.
4. Name the new pattern as UK Postal Area.
5. Hover your mouse over the Result box and right click. From the menu select Component and then area.
will then appear in the Result box.
6. To test the pattern, click the
button and type a postcode in the text box. If set up correctly, the result box should display just the area component of the postcode.
7. Click
to exit the pattern test and then click
again to save your pattern.
Step 2
The second step is to create a derived variable that can be used in conjunction with the UK Postal Area pattern.
1. Select the Variables icon
from the main Snap toolbar.
2. Click the
icon to create a new variable. Label the variable as ‘Area’.
3. The Type will be Derived and the Response will be Single.
4. Double click in the Label column, and add a code label of Birmingham.
5. Use the Tab key to move across to the Values column.
6. Type Q11 as UK Postal Area ==”B”
Birmingham postcodes contain the letter B as the area component, e.g. B12 4LT. A value of Q11 as UK Postal Area =”B” will count any postal area containing B e.g. BS35 3UW which is a Bristol postcode. Therefore it is necessary to search for an exact match using = =.
7. Tab again for the next code label which will be Bristol.
The value will be Q11 as UK Postal Area =”BS”
8. Tab again for the next code label which will be Reading.
The value will be Q11 as UK Postal Area =”RG”
9. To run the variable, click
which will display the results in the Counts column.
10. Click
to save the derived variable.
You can then use this new variable to create tables and charts