I am trying to learn R and want to bring in an SPSS file, which I can open in SPSS.
I have tried using read.spss
from foreign
and spss.get
from Hmisc
. Both error messages are the same.
Here is my code:
## install.packages("Hmisc")
library(foreign)
## change the working directory
getwd()
setwd('C:/Documents and Settings/BTIBERT/Desktop/')
## load in the file
## ?read.spss
asq <- read.spss('ASQ2010.sav', to.data.frame=T)
And the resulting error:
Error in read.spss("ASQ2010.sav", to.data.frame = T) : error reading system-file header In addition: Warning message: In read.spss("ASQ2010.sav", to.data.frame = T) : ASQ2010.sav: position 0: character `\000' (
Also, I tried saving out the SPSS file as a SPSS 7 .sav file (was previously using SPSS 18).
Warning messages: 1: In read.spss("ASQ2010_test.sav", to.data.frame = T) : ASQ2010_test.sav: Unrecognized record type 7, subtype 14 encountered in system file 2: In read.spss("ASQ2010_test.sav", to.data.frame = T) : ASQ2010_test.sav: Unrecognized record type 7, subtype 18 encountered in system file
I know this post is old, but I also had problems loading a Qualtrics SPSS file into R. R's read.spss code came from PSPP a long time ago, and hasn't been updated in a while. (And Hmisc's code uses read.spss(), too, so no luck there.)
The good news is that PSPP 0.6.1 should read the files fine, as long as you specify a "String Width" of "Short - 255 (SPSS 12.0 and earlier)" on the "Download Data" page in Qualtrics. Read it into PSPP, save a new copy, and you should be in business. Awkward, but free.
,
For me it works well using memisc!
Another solution not mentioned here is to read SPSS data in R via ODBC. You need:
RODBC
package in R.See the example here. However I have to admit that, there could be problems with very big data files.
I had a similar issue and solved it following a hint in
read.spss
help. Using packagememisc
instead, you can import a portable SPSS file like this:Similarly, for .sav files:
although in this case I seem to miss some string values, while the portable import works seamlessly. The help page for
spss.portable.file
claims:The importer mechanism is more flexible and extensible than read.spss and read.dta of package "foreign", as most of the parsing of the file headers is done in R. They are also adapted to load efficiently large data sets. Most importantly, importer objects support the labels, missing.values, and descriptions, provided by this package.
If you have access to SPSS, save file as .csv, hence import it with
read.csv
orread.table
. I can't recall any problem with .sav file importing. So far it was working like a charm both withread.spss
andspss.get
. I reckon thatspss.get
will not give different results, since it depends onforeign::read.spss
Can you provide some info on SPSS/R/Hmisc/foreign version?
You may also try this:
and if you want to read all files from one folder: