Import and Export 'SPSS', 'Stata' and 'SAS' Files

Import foreign statistical formats into R via the embedded 'ReadStat' C library, < https://github.com/WizardMac/ReadStat>.


haven

CRANstatus R-CMD-check Codecov testcoverage

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")

Related work

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

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("haven")

2.5.5 by Hadley Wickham, a year ago


https://haven.tidyverse.org, https://github.com/tidyverse/haven, https://github.com/WizardMac/ReadStat


Report a bug at https://github.com/tidyverse/haven/issues


Browse source code at https://github.com/cran/haven


Authors: Hadley Wickham [aut, cre] , Evan Miller [aut, cph] (Author of included ReadStat code) , Danny Smith [aut] , Posit Software , PBC [cph, fnd]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports cli, forcats, hms, lifecycle, methods, readr, rlang, tibble, tidyselect, vctrs

Suggests covr, crayon, fs, knitr, pillar, rmarkdown, testthat, utf8

Linking to cpp11

System requirements: GNU make, zlib: zlib1g-dev (deb), zlib-devel (rpm)


Imported by AgePopDenom, BEACH, BEMPdata, CEOdata, CUFF, DCC, DHS.rates, DIDHAD, DIDmultiplegtDYN, DIVINE, DedooseR, DescTools, Dire, EDCimport, EdSurvey, FAfA, FertNet, FocusGroup, GLMBasedRaschEstimation, HARplus, HIViz, ILSAmerge, ImportExport, LISTC, LearningStats, MappingCalc, NBDCtools, QuickExplore, RALSA, RCPA3, REDCapCAST, RcmdrMisc, Rilostat, Rmonize, SUMMER, StatsTFLValR, TwoWayFEWeights, adepro, amp.dm, asciiSetupReader, aweSOM, bpnreg, bulkreadr, calidad, canpumf, censo2022arg, ces, chms, chmsflow, clinCompare, clinDataReview, clinUtils, codebook, codebookr, complexr, connector, coreval, crosswalkr, cspp, dataMaid, dataReporter, datadictionary, dataganger, dataset, describedata, dosr, duawranglr, eatGADS, elaborator, electionsBR, enaho, essurvey, evalITR, fabR, fastreg, fetch, fluxible, formr, ggplotgui, ggseqplot, hildareadR, idcnrba, importinegi, ipumsr, ivDiag, jsmodule, labelled, lapop, lavaangui, libr, lmap, madshapR, mcmsector, mditools, measureR, misty, mitml, netCoin, nhanesR, odbr, opencis, opinAr, parquetize, pioneeR, projectLSA, rcdf, rdhs, recodeflow, repfun, retroharmonize, rfars, rio, ropercenter, sae4health, scf, sdcMicro, sdtmval, secuTrialR, sendigR, seqSHP, skewlmm, spada, statAfrikR, stepssurvey, synadam, tabbitR, tanner, tidyCDISC, tidyklips, tidyverse, tsg, vtable, webuse, wizaRdry, xSub, xlr, xportr.

Depended on by cchsflow.

Suggested by AdhereRViz, DiSCos, EpiQuestionR, HawaSpatial, HonestDiD, IRTC, MAICtools, MAIHDA, MVN, OneSampleMR, PNADCperiods, R4VN, Rbearcat, Rfuzzydid, Tplyr, ViewR, aNCA, artma, bedrock, bootmlm, bruceR, cNORM, cloudfs, clustra, compareGroups, crunch, csemGT, datasetjson, dataverse, datawizard, did2s, didimputation, drlate, egnyte, egor, epmfd, factorH, fauxnaif, fejiv, fixes, framework, frequency, gendercoder, ggeffects, gglyph, gtregression, healthbR, htetree, iNZightTools, ivdesc, ivdoctr, jmvReadWrite, labelr, lessR, lineager, logrx, manifestoR, marginaleffects, mariposa, mark, memapp, metasurvey, metatools, mhtopt, mice, mlr3shiny, modelsummary, msSPChelpR, nettskjemar, nonabsdid, opencpu, opendataformat, ordbetareg, parameters, prais, psyverse, public.ctn0094data, pulso, qbrms, rCoreGage, regulog, resourcer, rolescry, rtemis, rvisual, sampleVADIR, saros, saros.base, simPop, simaerep, sjPlot, sjlabelled, sjmisc, skimr, slxr, spicy, sreg, summarytools, surveyframe, syntaxr, tablet, tflmetaR, tidytlg, tinytrail, trialdiff, troopdata, versioning, weightflow, xplorerr, xtvfreg, yamlet, zmisc.

Enhanced by memisc, optmatch.


See at CRAN