By Ruben Geert van den Berg on March 28, 2017 under SPSS Date FAQ.

Compute Age

In some cases, one would like to COMPUTE respondents' age given their birthday. As long as birthday is an actual date variable, age is readily calculated by using the DATEDIFF function. Copy-paste-run the syntax below for a demonstration of DATEDIFF.

SPSS Datediff Syntax Example

*1. Create test data.

data list free/bday(a10).
begin data
end data.

*2. Convert birthday into date variable.

alter type bday(edate10).

*3. Compute current age.

compute age_years=datediff($time,bday,"years").
compute age_months=mod(datediff($time,bday,"months"),12).


Comment on this Tutorial

*Required field. Your comment will show up after approval from a moderator.

This Tutorial has One Comment: