Import data to R from SAS, SPSS and Stata with Haven

October 6, 2016

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

Regardless of the tool you use to analyse data, you'll often have to access data living in file formats generated by other tools. The "haven" package from RStudio  allows you to import and export data in SAS, SPSS and Stata formats. Version 1.0 was released on October 4, and is now available on CRAN. Haven is also installed as part of the tidyverse.

Haven augments the base R foreign package with additional formats. The core read/write engine is the ReadStat package, and it provides support for:

  • SAS binary files (SAS7BDAT), including compressed files
  • SPSS .sav and .por files
  • Stata files

Haven takes special care in handling missing values in these file formats, and includes tools for extracting information from the specialized missing value representations in each format. It also has improved support for handling dates and times. (See the blog post announcing Haven for details.)

For those working in the pharmaceutical industry, there's one unfortunate omission in ReadStat (and therefore Haven) thus far. While the FDA does not mandate that SAS be used for analysis in clinical trials, it does mandate that the data be provided in the SAS Transport File (XPORT) format, which is an open standard. Hopefully this will be added in a future release, but in the meantime you can read XPORT files with the base read.xport function, and write them with the SASxport package.

For more information on Haven, check out the Haven website. Thanks to Hadley and the RStudio team for providing this useful functionality to R!


To leave a comment for the author, please follow the link and comment on their blog: Revolutions. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)