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 uses the Snap WebHost edition of the Crocodile survey which is provided with Snap.

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.
Enter zip / postcode

Variable Properties | Postcode uk

  1.  Select Tailor | Patterns from the main Snap toolbar.

    Patterns window

  2. Scroll down to the ‘Postcode UK’ pattern and highlight it.
  3. Click [Clone] to make a copy of it.
  4. Name the new pattern as UK Postal Area.
  5. Click in the Result box and clear the details. Right click, from the menu, select Component and then area, {area} will then appear in the Result box.

    Pattern Properties | Result | select Component then area

  6. To test the pattern, click the Test... 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 OK button to exit the pattern test and then click OK button 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 that you have created above.
Pattern Match

  1. Select the Variables icon VariablesButton from the main Snap toolbar.
  2. Click the plus | add icon to create a new variable. Make a note of the name and enter ‘Area’ as the Label
  3. The Type will be Derived and the Response will be Single.
  4. In the bottom half of the screen, 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 Count icon which will display the results in the Counts column.

    Variable Details

  10. Click Save to save the derived variable.You can then use this new variable to create tables and charts.

If there is a topic you would like a worksheet on, email to snapideas@snapsurveys.com