WinCross provides a way to extract the month, day or year elements from a formatted date variable. This allows the individual elements of the date to be assigned to a declared variable within the Glossary.
SPSS Date Variables:
If you have a date variable called STARTDATE, you can use the expressions STARTDATE:_MONTH, STARTDATE:_DAY and STARTDATE:_YEAR2 to refer to the individual elements within the date. For a four-digit year, use STARTDATE:_YEAR4.
Numeric Variables (SPSS or non-SPSS):
The WinCross date extraction can also be used to extract the month, day and year from numeric data variables, provided the values are formatted in an acceptable format.
The functions can be used directly when numeric variables are of the form DDMMYY or DDMMYYYY.
For example: Consider a numeric variable called MYDATE that contains the data value 31122014. The construct MYDATE:_YEAR2 returns "14", MYDATE:_YEAR4 returns "2014", MYDATE:_MONTH returns "12", and MYDATE:_DAY returns "31".
Tip: If your data variable contains values in the form MMDDYYYY (or MMDDYY), you can still extract the month, day and year, but because WinCross assumes DDMMYYYY format, the MONTH function would need to be used to extract the day, and the DAY function would extract the month. |
Strings Variables (SPSS or non-SPSS):
The WinCross date extraction can also be applied to string variables that contain date expressions. Both two-digit and four-digit years are supported, and all types of separators (dashes, slashes, dots, etc.) can be used.
The functions can be used directly when string variables are of the form DDMMYY or DDMMYYYY.
For example: Consider a string variable called ENDDATE that contains the string value 31-12-2014. The construct ENDDATE:_YEAR2 returns "14", ENDDATE:_YEAR4 returns "2014", ENDDATE:_MONTH returns "12", and ENDDATE:_DAY returns "31".
Tip: If your data variable contains values in the form MMDDYYYY (or MMDDYY), you can still extract the month, day and year, but because WinCross assumes DDMMYYYY format, the MONTH function would need to be used to extract the day, and the DAY function would extract the month. |
_YEAR4, _YEAR2, _MONTH and _DAY are all WinCross Reserverd Key Words.
The variable used for extracting date information can be a variable defined in the Glossary but the same WinCross formatting assumptions apply.
Related topics: