The The R Primer logo Primer

Import a SAS/SPSS/Systat/Stata dataset

You want to import an SPSS dataset into R

Solution: Datasets stored by the SPSS "save" and "export" commands can be read by the read.spss function from the foreign package. To read an SPSS dataset saved in the spssfilename.sav file we use the following command in R:


> library(foreign)
> indata <- read.spss("spssfilename.sav", to.data.frame = TRUE)
The functions read.xport, read.dta, and read.systat have the same functionality and are used to import SAS xport datasets, Stata datasets, and Systat datasets, respectively.

See rules 1.10, 1.11, 1.12, and 1.13 in The R Primer for more information.

Back to tips.