How to open SPSS .sav files in R with haven

Checked against the official docs on

Install the haven package, then read_sav() loads your SPSS data into R with value labels and special missing values kept. write_sav() saves back to .sav.

  1. Install haven

    In R, run install.packages("haven"), or install.packages("tidyverse") to get haven with the rest of the tidyverse.

  2. Load it

    Run library(haven).

  3. Read your SPSS file

    df <- read_sav("yourfile.sav") reads a .sav file. For older portable files, use read_por("yourfile.por").

  4. Work with value labels

    Labelled values come in as haven's labelled() class, so the original labels aren't lost. Use as_factor() to turn them into factors. Special missing values are preserved.

  5. Save back to SPSS if you need to

    write_sav(df, "out.sav") writes a .sav file that colleagues can open in SPSS.

Watch out for

  • Dates and times are converted to R date/time classes, and character vectors are not converted to factors.
  • haven also reads Stata .dta (up to version 15) and SAS files, if you're moving from those too.

Sources: haven.tidyverse.org. Menus and options can change between versions; if a step doesn't match what you see, follow the linked page.