How do I import SPSS, Stata, or SAS data files in R?
To import SPSS, Stata, or SAS data files in R, first install and load
foreign. The functions
read.dta() , and
read.xport() of the package
SPSS, Stata, and SAS Transport data files, respectively.
Use the following syntax to import the three types of data files:> spssdata <- read.spss("C:/temp/spssfile.sav") > statadata <- read.dta("C:/temp/statafile.dta") > sasdata <- read.xport("C:/temp/sasfile.xpt")
The three data files are saved as R objects, called
sasdata. The data sets are stored in
R's memory and can be called for statistical analysis during the
current R session.
Note: R cannot import SAS permanent data set
.sas7bdat) files. Use Stat/Transfer
to convert SAS permanent data set files to other file formats and then
import them to R. At Indiana University, the Stat/Transfer software is
available on Quarry and the Windows Student Technology Center (STC)
If you have questions about using statistical and mathematical software at Indiana University, email UITS Research Analytics (formerly known as the Stat/Math Center). Research Analytics is located on the IU Bloomington campus at Woodburn Hall 200, and is open for consultation by appointment Monday-Friday 9am-5pm. For more, visit Research Analytics on the web, or call 812-855-4724 (IUB) or 317-278-4740 (IUPUI).
Last modified on October 18, 2012.