0

I have tried using spss.get from Hmisc. Here is my code:

    install.packages("Hmisc")
    library(Hmisc)
    mydata <- spss.get("C:\\good good study\\comscore\\purchase.sav", use.value.labels = TRUE)

the output is shown with warning message which is as follows:

> mydata <- spss.get("C:\\good good study\\comscore\\purchase.sav", use.value.labels = TRUE)
Warning messages:
1: In read.spss(file, use.value.labels = use.value.labels, to.data.frame = to.data.frame,  :
C:\good good study\comscore\purchase.sav: Unrecognized record type 7, subtype 14 encountered in system file
2: In read.spss(file, use.value.labels = use.value.labels, to.data.frame = to.data.frame,  :
C:\good good study\comscore\purchase.sav: Unrecognized record type 7, subtype 18 encountered in system file

My initial date in spss is as follow: date in spss is correct

However, when I use spss.get in R, the data for date becomes garbled: date become garbled in R

selva
  • 1,175
  • 1
  • 19
  • 39

1 Answers1

5

This is a number of seconds from some specific time what you see in R. You can convert it to date or time. For example:

z <- c(10485849601, 10477641600, 10561104000, 10562745600)
as.POSIXct(z, origin="1582-10-14", tz="GMT")

The value "1582-10-14" for the origin is taken from the SPSS Statistics Base manual:

Internally, all date and time format values are stored as a number of seconds: date formats (e.g., DATE, ADATE, SDATE, DATETIME) are stored as the number of seconds since October 14, 1582; time formats (TIME, DTIME) are stored as a number of seconds that represents a time interval (e.g., 10:00:00 is stored internally as 36000, which is 60 seconds x 60 minutes x 10 hours).

https://www.ibm.com/support/knowledgecenter/en/SSLVMB_23.0.0/spss/base/syn_date_and_time_date_time_formats.html

For time values probably the best option is to use the chron library. See the example:

require(chron)
y <- c(58130, 10981)
chron(times. = y / (24*60*60))

Have you tried the haven package for reading the SPSS data?

djhurio
  • 5,437
  • 4
  • 27
  • 48
  • Thanks for your answer. I have convert the data for date into correct format using your code. Further, I want to ask how to convert the data for time into correct format? – Jilei Zhou Aug 29 '16 at 15:46
  • Thanks for your code @djhurio. How do you know the value of `origin` option? – jgarces Jan 29 '20 at 11:07
  • 1
    @jgarces, I got this information from the SPSS Statistics manual: "Internally, all date and time format values are stored as a number of seconds: date formats (e.g., DATE, ADATE, SDATE, DATETIME) are stored as the number of seconds since October 14, 1582;" https://www.ibm.com/support/knowledgecenter/en/SSLVMB_23.0.0/spss/base/syn_date_and_time_date_time_formats.html – djhurio Jan 29 '20 at 17:13