This content describes Snap 11. For Snap 10, the equivalent page will be in Snap 10 help

Next Topic

Book Contents

Book Index

Calculating age from a date of birth

These instructions tell you how to create variables to calculate the respondent's age from their date of birth and then put the respondents into age bands, based on the difference between a date of birth variable and the date function today. The instructions also apply if you have another date question in the questionnaire, which you want to use instead of today.

For this example, the date of birth variable is Q1. It assumes a four-digit year.

  1. Click New button to create a new variable. Specify the Variable Details as:

    Name: Age

    Label: Calculated age in years

    Type: Derived (the variable will derive its data from other existing variables).

    Response: Quantity (the response will be a numeric value for each case).

    New vaariable field getting context aspect

  2. Specify the Code Values to calculate the number of years:

Code

Code Label

Value

NA

Not Asked

Q1 Missing

OK

Valid

(today-Q1a)\365.25

Note the use of \ to extract the whole number of years.

  1. Click Save button to save the variable. You can then use this to analyse respondents' ages.

    The Not Asked value is specified to ensure that the calculation is only performed if data exists for the date question.

  2. To band the respondents into age groups, create a new variable:

    Name: Agegroup

    Label: Age groups

    Type: Derived

    Response: Single (each respondent will only fall into one of the new codes).

    New vaariable field getting context aspect

  3. Specify the Code Details:

    Code

    Code Label

    Value

    1

    Up to 18

    Age <= 18

    2

    19 to 24

    Age <= 24

    3

    25 to 34

    Age <= 34

    4

    35 to 44

    Age <= 44

    5

    45 to 54

    Age <= 54

    6

    55 to 64

    Age <= 64

    7

    65 plus

    true

    The codes are assigned in order, so all responses that have not been sorted into previous bands appear as 65 plus.

  4. Click Save button to save the variable.

See Also

Date formats

Date Functions

Categorising date responses

Using a date function to determine the day of the week of a date