tags:

views:

75

answers:

3

Hi All,

Probably a basic answer. 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

Any help will be much appreciated.

Brock

+2  A: 

It looks like the R read.spss implementation is incomplete or broken. R2.10.1 does better than R2.8.1, however. It appears that R gets upset about custom attributes in a sav file even with 2.10.1 (The latest I have). R also may not understand the character encoding field in the file, and in particular it probably does not work with SPSS Unicode files.

You might try opening the file in SPSS, deleting any custom attributes, and resaving the file. You can see whether there are custom attributes with the SPSS command

display attributes.

If so, delete them (see VARIABLE ATTRIBUTE and DATAFILE ATTRIBUTE commands), and try again.

HTH, Jon Peck

Jon Peck
Used display attributes. in a syntax file and I get a warning telling me there are no attributes to display. Some of the string fields are 2000 length, should that matter?
Btibert3
Hi Jon - I tried Deleting the attributes with the following syntax. Did have a few, removed them, still no luck*//// Display the Custom attributes.DISPLAY ATTRIBUTES.*//// DELETE all for every variable with custom attributes.VARIABLE ATTRIBUTE VARIABLES=GameID TO OUTCOME_DIFF DELETE=$ODBC.Name.VARIABLE ATTRIBUTE VARIABLES=GameID TO OUTCOME_DIFF DELETE=$ODBC.Table.VARIABLE ATTRIBUTE VARIABLES=GameID TO OUTCOME_DIFF DELETE=$ODBC.Size.VARIABLE ATTRIBUTE VARIABLES=GameID TO OUTCOME_DIFF DELETE=$ODBC.Type.*//// Confirm that they are removed and manually save.DISPLAY ATTRIBUTES.
Btibert3
+1  A: 

If you have access to SPSS, save file as .csv, hence import it with read.csv or read.table. I can't recall any problem with .sav file importing. So far it was working like a charm both with read.spss and spss.get. I reckon that spss.get will not give different results, since it depends on foreign::read.spss

Can you provide some info on SPSS/R/Hmisc/foreign version?

aL3xa
2.10.1 - updated all packages. I am getting the SPSS file from another software.
Btibert3
Which one, if we may know? I'm not interested in particular SPSS version "per se", I just need to know is it SPSS or PASW file... maybe it has something to do with changes made latest releases... Dunno... =(
aL3xa
PASW - created from survey software Qualtrics and modified/saved in PASW 18
Btibert3
Try saving the file in SPSS compatible version... if applicable. Then import it with `read.spss`. BTW, you can always export it as a plain text (ASCII) file.
aL3xa
It seems that there's no support for PASW files in R whatsoever... You're not alone: http://www.mail-archive.com/[email protected]/msg04648.html
aL3xa
A: 

1)

I've found the program, stat-transfer, useful for importing spss and stata files into R.

It resolves the issue you mention by converting spss to R dataset. Also very useful for subsetting super large datasets into smaller portions consumable by R. Not free, but a very useful tool for working with datasets from different programs -- especially if you don't have access to them.

2)

Memisc package also has an spss function worth trying.

Robert