1

With the foreign package, I'm reading in a .sav file. When I open the file with PSPP there are 95 variables. However, read.spss("file") responds with a list of 353 variables. The extra variables are blank filled fields with 220 spaces. Has anyone ever experienced this?

Before you ask, I am unable to provide a reproducible example, as the data file and its contents are proprietary.

One obvious solution would be to search for list elements that contain only spaces and set them the list element to NULL or each element with 220 spaces to NA and then drop NA columns.

But I'd like to avoid having to further post process my files if necessary. Does anyone have a fix for this?

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
  • 1
    You could try exporting to a 'portable' file (*.por) in SPSS, and open this in R (also with `read.spss`). I read somewhere this works often more reliably, however just now it failed me on a certain SPSS dataset, while it worked on a second one. Or just try saving your dataset to a new file, doing something like that helped me once, apparently it rewrites the whole file structure which might clean up problems. Good luck! – ROLO Oct 11 '11 at 11:09

1 Answers1

3

I've had something similar before. This happened when the data was exported from SPSS CATI (the field interview application), rather than the SPSS we know and love.

In my case the resolution was to play around with the arguments to read.spss. I found that setting use.missings=FALSE resolved the problem, i.e. something like:

read.spss(global$datafile, to.data.frame=TRUE, use.missings=FALSE)

Good luck, and my sympathy. I know how frustrating this was for me.

Andrie
  • 176,377
  • 47
  • 447
  • 496
  • In my case, use.missing=F did not work. Seems to the issue associated with string>255 chars. see more at bugs.r-project.org/bugzilla3/show_bug.cgi?id=15152 and it is not going to be fixed. the haven package seems to work well with this situation. – Jerry T May 17 '18 at 18:44