In some cases, one would like to calculate 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
SPSS Datediff Syntax Example
data list free/bday(a10).
*2. Convert birthday into date variable.
alter type bday(edate10).
*3. Compute current age.
- Somebody's age is obviously the current date minus his birthday. In SPSS, the system variable
$timeholds the current date and dates can be subtracted using
- In the latter, a time unit (such as year) can be specified. Note that the result is always truncated.
- Since the example presented here focusses on readability, only years and months were calculated. If age is to be used in any calculations, it may be a better idea to use a fixed date instead of
$timeand smaller time units (for example just "days").