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
On Wed, 3 Mar 2004 11:21:12 -0500 (EST) "Gabor Grothendieck" <ggrothendieck at myway.com> wrote:> > > 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 >The spss.get function in the Hmisc packages allows you to specify a vector of variable names that are to be automatically converted to dates (POSIXct form). It calls read.spss to to the main work. Speaking of read.spss, which I have found handles labels and value labels very well, I am having a difficulty with character variables ending up as factors even when the number of levels equals the number of observations. I would be nice to have an option to keep character variables as-is (the sas.get function in Hmisc provides many options for this). Frank Harrell
> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.] On Behalf Of > torsten at hothorn.deethz.ch > Sent: Wednesday, March 03, 2004 6:27 PM > To: Peter Dalgaard > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] read.spss and time/date information > > > > > On Wed, 3 Mar 2004, Peter Dalgaard wrote: > > > Torsten Hothorn <Torsten.Hothorn at rzmail.uni-erlangen.de> writes: > > > > > Could anyone give me a a hint how I can convert 13264300800 to > > > 2003/02/11 again, please? > > > > > ISOdate(1582,10,14) + 13264300800 > > [1] "2003-02-11 13:00:00 CET" > > > ISOdate(1582,10,14) + 13142476800 > > [1] "1999-04-03 14:00:00 CEST" > > > > [October 14, 1582 is Day 1 of the Gregorian calendar.] > > > > I tried January 1th 1970 as "baseline" but I never would have > dreamed of October 14, 1582.This is the day the present Gregorian calendar was instituted, replacing the old Julian that did not have leap years. So it is actually quite sensible as it is the earliest possible date that is in unbroken sequence to present times. Actually I am amazed that this has not been chosen as the natural origin for any of the R-pakages... Bendix Carstensen> > Thanks to all responders! > > Torsten > > > -- > > 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 > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html >