RepositoryC
TI

tidyverse/haven

Read SPSS, Stata and SAS files from R

461stars
121forks
5issues
3views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: stata

#1 Repository of the week

1
TINIX TRENDING·Topic: spss

#1 Repository of the week

2
TINIX TRENDING·Topic: sas

#2 Repository of the week

haven

CRAN
status R-CMD-check Codecov test
coverage

Overview

Haven enables R to read and write various data formats used by other statistical packages by wrapping the fantastic ReadStat C library written by Evan Miller. Haven is part of the tidyverse. Currently it supports:

  • SAS: read_sas() reads .sas7bdat + .sas7bcat files and read_xpt() reads SAS transport files (versions 5 and 8). write_xpt() writes SAS transport files (versions 5 and 8).

  • SPSS: read_sav() reads .sav files and read_por() reads the older .por files. write_sav() writes .sav files.

  • Stata: read_dta() reads .dta files (up to version 15). write_dta() writes .dta files (versions 8-15).

The output objects:

  • Are tibbles, which have a better print method for very long and very wide files.

  • Translate value labels into a new labelled() class, which preserves the original semantics and can easily be coerced to factors with as_factor(). Special missing values are preserved. See vignette("semantics") for more details.

  • Dates and times are converted to R date/time classes. Character vectors are not converted to factors.

Installation

# The easiest way to get haven is to install the whole tidyverse:
install.packages("tidyverse")

# Alternatively, install just haven:
install.packages("haven")

Usage

library(haven)

# SAS
read_sas("mtcars.sas7bdat")
write_xpt(mtcars, "mtcars.xpt")

# SPSS
read_sav("mtcars.sav")
write_sav(mtcars, "mtcars.sav")

# Stata
read_dta("mtcars.dta")
write_dta(mtcars, "mtcars.dta")
  • foreign reads from SAS XPORT, SPSS, and Stata (up to version 12) files.

  • readstat13 reads from and writes to all Stata file format versions.

  • sas7bdat reads from SAS7BDAT files.

Code of Conduct

Please note that the haven project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Similar Projects

Discover other similar projects and AI models.

RepositoryR
gesistsa/rio

🐟 A Swiss-Army Knife for Data I/O

621
Oct 23, 2026
RepositoryR
larmarange/labelled

Manipulating labelled vectors in R

82
Aug 21, 2026
RepositoryR
ddotta/parquetize

R package that allows to convert databases of different formats to parquet format

80
Nov 24, 2025
RepositoryR
sfirke/janitor

simple tools for data cleaning in R

1.5k
Nov 23, 2026
RepositorySAS
HHS-AHRQ/MEPS

This repository provides example code for loading and analyzing data from AHRQ's Medical Expenditure Panel Survey (MEPS). More information about the survey and access to public use data files is available on our website

194
Jun 9, 2026
RepositoryC
Roche/pyreadstat

Python package to read and write sas, spss and stata files into/from pandas and polars data frames. It is a wrapper for the C library readstat.

432
Nov 25, 2026
RepositoryJupyter Notebook
microsoft/ML-For-Beginners

12 weeks, 26 lessons, 52 quizzes, classic Machine Learning for all

92.5k
Nov 7, 2026
RepositoryScala
apache/spark

Apache Spark - A unified analytics engine for large-scale data processing

44.7k
Dec 2, 2026
RepositoryPython
meta/prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.

20.5k
Nov 24, 2026