For time calculations (such as the number of days between two dates) proper date variables are needed. In some cases, the digits of a numeric variable may represent year, month and day. This tutorial shows how to convert this format into an actual date variable.
Convert Numbers to SPSS Date Variables
SPSS Date Function Syntax Example
data list free/date(f8).
*2. Convert into date format.
compute realdate = date.dmy(mod(date,10**2),tru(mod(date,10**4)/10**2),tru(date/10**4)).
SPSS Date Function Explanation
- In SPSS, a date variable holds the number of seconds since (roughly) 1582.
- For any (day, month, year) combination, the function
DATE.DMYcalculates this number.
- It will be displayed as a normal date if its
FORMATis set (for example) to
- For the example data, the day, month and year correspond to the last, middle and first digits of the number.
- These are extracted by combining
MODULUSAlso, see Modulus (General Concept).
- Like so, new variables holding the day, month and year can be created and these can be used in the
- Alternatively, the syntax extracting day, month and year can be placed directly into
DATE.DMYas is done here.