statfile.tools

How to open a .sav file in R

R reads SPSS files well — the modern route is the haven package, which preserves variable labels and value labels as attributes. Here is the short version, what the labelled columns mean, and a no-install fallback when you just need to see the data.

The short answer: haven::read_sav()

Install haven once with install.packages("haven"), then load a file with df <- haven::read_sav("survey.sav"). The result is a tibble in which each column keeps its SPSS metadata: the variable label is stored in the "label" attribute, and coded categories arrive as haven's labelled class, which keeps both the numeric codes and the text labels.

To work with categories as R factors, convert them explicitly: haven::as_factor(df) turns every labelled column into a factor using the value labels, while haven::zap_labels(df) does the opposite and strips labels to leave plain numeric codes. Choosing one of these early avoids the common confusion of a column that prints like a number but summarises like a category.

The older route: foreign::read.spss()

Base R's foreign package also reads .sav files: read.spss("survey.sav", to.data.frame = TRUE, use.value.labels = TRUE). It works, but it is no longer actively developed, struggles with newer SPSS features such as long strings and some encodings, and flattens the metadata that haven preserves. For new work, haven is the better default; reach for foreign only when replicating older scripts.

Whichever reader you use, check the encoding if you see garbled accented characters. haven::read_sav() accepts an encoding argument (for example encoding = "latin1") for files written by very old SPSS versions that predate Unicode mode.

When you don't want to write code

If the goal is simply to inspect the file — check the variables, read the labels, eyeball the data — you do not need R at all. statfile.tools opens .sav files directly in the browser with a Data View and a Variable View, and can export to CSV for import anywhere. Because the file is parsed locally and never uploaded, it is safe for restricted-use data.

Frequently asked questions

Does read_sav keep value labels?+

Yes. haven stores them in a labelled vector class; use as_factor() to convert coded columns to factors with the label text, or zap_labels() to keep raw codes.

Why do my .sav dates look like numbers in R?+

haven converts SPSS date variables to R Date or POSIXct automatically. If you read the file with a low-level tool instead, you may see raw SPSS date values, which count seconds since 14 October 1582 and need re-basing.

Can R write .sav files too?+

Yes — haven::write_sav(df, "out.sav") writes a .sav that SPSS opens, preserving labels from labelled columns.

Convert this format