简体   繁体   中英

Data not matching when imported from spss into r and spss into sas

I've been trying to import a spss (.sav) file into r and sas and match the data. Date variable is in huge numbers, so am converting it in R. I'.m getting the differences in date and time variables. One of the record where it shows start date in r is missing in sas. All the time stamps are 12.00.00 in r while 00.00.00 in sas. Can anyone please help me out where I am getting it wrong?

This is the code I used in R:

library("memisc")
data<-as.data.set(spss.system.file('aa.sav'))
library("chron")
data$formdate<-as.chron(ISOdate(1582, 10, 14) + data$formdate)
data$randdate<-as.chron(ISOdate(1582, 10, 14) + data$randdate)
data$med1start<-as.chron(ISOdate(1582, 10, 14) + data$med1start)
data$med1end<-as.chron(ISOdate(1582, 10, 14) + data$med1end)
data

and this is the code I used in SAS

proc import datafile="C:\ofc\aa.sav" out=mydata dbms = sav replace;
run;

To take a look of how data is both on R and SAS, follow this link Any help would be appreciated. Thanks.

The datetimes in SAS are correct. The SPSS numbers represent the number of seconds since midnight, October 14, 1582. The reason R is adding 12 hours to the values is that the default value of the optional hour argument to the ISOdate function is 12 :

ISOdate(year, month, day, hour = 12, min = 0, sec = 0, tz = "GMT")

If you use ISOdate(1582, 10, 14, 0) instead, you should get the right answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM