ARCHIVED: 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 the package foreign. The functions read.spss(), read.dta(), and read.xport() of the package foreign import 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 spssdata, statadata, and 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 (.ssd or .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) computers.

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 2015-07-01.

  • 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.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.