I am using read.spss in the foreign package to read an SPSS save file. For date variables I get huge values such as 11489990400. Does anyone know how to convert these values to R POSIXct date objects? Thanks in advance -Frank platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 6.1 year 2002 month 11 day 01 language R Package: foreign Priority: recommended Version: 0.5-10 Date: 2003-03-01 --- Frank E Harrell Jr Prof. of Biostatistics & Statistics Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat
On Mon, 21 Apr 2003, Frank E Harrell Jr wrote:> I am using read.spss in the foreign package to read an SPSS save file. > For date variables I get huge values such as 11489990400. Does anyone > know how to convert these values to R POSIXct date objects? Thanks in > advance -Frank >I believe it is ISOdate(1584,10,14)+11489990400 that is, the dates are seconds since 14 October 1584 I don't know if R and SPSS necessarily agree on how long ago that was on all machines, though. -thomas
Frank E Harrell Jr <fharrell at virginia.edu> writes:> I am using read.spss in the foreign package to read an SPSS save file. For date variables I get huge values such as 11489990400. Does anyone know how to convert these values to R POSIXct date objects? Thanks in advance -FrankGoogle is your friend. 3rd item from a search on spss+dates is Statistical Packages at MIMAS: SPSS - date handling and the Year ... Conclusions. SPSS stores dates internally as elapsed seconds since 00:00:00 on 14 October 1582, the first allowable date being 15 October 1582. So who's born Nov.21 1946? -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Many thanks to Scot McNary, Thomas Lumley, and Peter Dalgaard. ISOdate(1584,10,14) + x worked like a charm in converting SPSS dates to POSIX. I have written a little function spss.get that calls read.spss and makes the needed changes in date/time variables. It also converts integer-valued variables to be stored as integers and associates variable labels with each variable as Hmisc expects (as with sas.get). spss.get will be in the next version of the Hmisc package. read.spss works extremely well for us. I especially appreciate how it sets up value labels in factors. It was also able to import an SPSS files that S-Plus 6 could not import properly. Thanks to Saikat DebRoy for writing read.spss. --- Frank E Harrell Jr Prof. of Biostatistics & Statistics Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat