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.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. Research Analytics is located on the IU Bloomington campus at Woodburn Hall 200, and is open for consultation by appointment Monday-Friday 9am-5pm.
This is document azuw in the Knowledge Base.
Last modified on 2014-06-25.
- Fill out this form to submit your issue to the UITS Support Center.
- Please note that you must be affiliated with Indiana University to receive support.
- All fields are required.