Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
writing dates to sav #25
I am unable to write dates using the haven package. I've tried formatting the dates as dates, POSIX, and character types. Any ideas?
When I export Date vector from R to SPSS it gives me the number of days between the date and January 1, 1970. I can write very simple syntax in SPSS to correct this. Figured this tidbit may help on your end!
If you look at the screenshot above, you will see the first case in the "date" variable is 16336. January 1, 1970 + 16336 days = September 23, 2014!
Note that SPSS does not support time zones or daylight saving time. R does, so the following results in the correct answer (23 hours instead of 24 hours) (in my default time zone):
Because the times may be used for calculations after exporting to SPSS, I think it’s better to save all date-times as UTC date-times. Here’s a function that can be used (for
This converts the date-time into the number of seconds sincce 1582-10-14, i.e. the internal format SPSS uses for all date-times (and dates). Any calculations done in SPSS would then work correctly. Example:
For dates, the following should do the trick:
Having an option for saving the date-times in ‘local time’ would also be nice, for applications where one only wants to see a date-time in SPSS, not doing any calculations on them (or only doing within-day day-time calculations, e.g. calculating hours worked). This can be accomplished by