[R] read.spss and time/date information

Gabor Grothendieck ggrothendieck at myway.com
Wed Mar 3 17:21:12 CET 2004



I don't use SPSS but following through on your detective work 
can provide the likely answer.

First note that both date numbers are evenly divisible by the number 
of seconds in a day, i.e. 24*60*60.  This suggests that these numbers
are seconds since some origin.

Since we know "2003/02/11" corresponds to 13264300800 we deduce that
the origin must be 

   spss.orig <- as.POSIXct("2003/02/11") - 13264300800

so  spss.orig+x  gives the POSIXct date if x is the SPSS number.

For example,

> spss.orig <- as.POSIXct("2003/02/11") - 13264300800
> spss.orig + c(13264300800, 13142476800)
[1] "2003-02-11 Eastern Standard Time" "1999-04-03 Eastern Standard Time"


An alternative might be to do this all in the GMT time zone:

spss.orig <- as.POSIXct("2003/02/11", tz="GMT") - 13264300800
format(spss.orig + c(13264300800, 13142476800), tz="GMT")


---
Date:   Wed, 3 Mar 2004 15:57:10 +0100 (CET) 
From:   Torsten Hothorn <Torsten.Hothorn at rzmail.uni-erlangen.de>
To:   <r-help at stat.math.ethz.ch> 
Subject:   [R] read.spss and time/date information 

 

Hi,

I could not find any information on how `read.spss' deals with date
information. As an example, I created a file containing two variables,
one numeric (values = (1, 2)) and one of type "Datum" in SPSS (german
version with values "11.02.2003" and "03.04.1999" and I get in R:

SPSSfile = url("http://www.imbe.med.uni-erlangen.de/~hothorn/dates.sav";, "rb")
SPSSdata = readBin(SPSSfile, "numeric", n = 10000)
writeBin(SPSSdata, con = "dummy.sav")
library(foreign)
read.spss("dummy.sav")

$DUMMY
[1] 1 2

$DATE
[1] 13264300800 13142476800

attr(,"label.table")
attr(,"label.table")$DUMMY
NULL

attr(,"label.table")$DATE
NULL


Could anyone give me a a hint how I can convert 13264300800 to 2003/02/11
again, please?

Best,

Torsten




More information about the R-help mailing list