Changing a variable type from string or numeric to date/time
#Stat transfer variables in data rows how to#
The following sections outline how to define a variable as date/time based on the variable’s current type. However, the procedure for defining a variable as date/time depends on its currently defined type (e.g., string, numeric, date/time). It is important to specify which variables in your data are dates/ times so that SPSS can recognize and use these variables appropriately. ( Source) In previous versions, these date formats would not recognize dates that did not contain the appropriate delimiters. Note: As of SPSS version 24, the above date formats will correctly recognize date strings without delimiters as long as the lengths of the other elements are correct (i.e., leading zeroes where necessary in the day, month, hour, minute, and second, so that those components are each two characters long). This is one of the benefits of using date-time variables to represent dates and durations: they give us the option to change how how the data is displayed without needing to do the conversion arithmetic ourselves. When we used the MTIME format, it knew that 29 hours, 14 minutes is equal to (29*60) + 14 = 1754 minutes. When we used the DTIME format, it knew that 29 hours should "roll over" to 1 day, 5 hours.
![stat transfer variables in data rows stat transfer variables in data rows](https://alanarnholt.github.io/PDS-Bookdown2/graphics/exmedicalrecords.jpg)
Notice how in the column of examples, SPSS took the same underlying data and automatically converted the time units based on the formats we chose. You will replace these with the appropriate number to use for the width of the date. The letter w denotes the number of "columns" (typically the number of characters in the input string), and the letter d represents the number of decimal places, if present. Just as with date formats, the "general form" of the format name contains w (or w.d).
![stat transfer variables in data rows stat transfer variables in data rows](https://cdn.graphpad.com/assets/0.61.0/images/srcset/prism-michaelis-w1102-800.png)
![stat transfer variables in data rows stat transfer variables in data rows](https://machinelearningmastery.com/wp-content/uploads/2017/06/Line-Plots-of-Air-Pollution-Time-Series.png)
![stat transfer variables in data rows stat transfer variables in data rows](https://www.lifewire.com/thmb/-C01gTAPDnpPj5_kRAeLz6eVtE4=/1500x1000/filters:fill(auto,1)/How-to-Pass-Arguments-to-a-Bash-Script-2200571-final2-be3eeccc278244bfbadce52ee4a4a14e.png)
A format is a named, pre-defined pattern that tells SPSS how to interpret and/or display different types of variables. When reading data containing dates or using certain date-time functions, we need to tell SPSS which date format to use, so that it knows how to correctly parse the components of the input string.