Skip to content
Back to skills

Haven

ASecurity

R haven package for SPSS, Stata, SAS files. Use for reading/writing .sav, .dta, .sas7bdat files with labels.

  • 5 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 4, 2026
data

Security analysis

A100/100

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill haven --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Haven?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Haven
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-haven/badge)](https://www.skillsdirectory.com/skills/leolin990405-haven)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: haven
description: R haven package for SPSS, Stata, SAS files. Use for reading/writing .sav, .dta, .sas7bdat files with labels.
---

# haven Package

Read and write SPSS, Stata, and SAS files.

## Read Files

```r
library(haven)

# SPSS
spss <- read_sav("data.sav")
spss <- read_spss("data.sav")  # alias

# Stata
stata <- read_dta("data.dta")
stata <- read_stata("data.dta")  # alias

# SAS
sas <- read_sas("data.sas7bdat")
sas_xpt <- read_xpt("data.xpt")  # transport
```

## Write Files

```r
write_sav(df, "output.sav")
write_dta(df, "output.dta")
write_xpt(df, "output.xpt")
```

## Labels

```r
# Value labels
x <- labelled(c(1, 2, 3), c(Low = 1, Med = 2, High = 3))
val_labels(x)

# Variable labels
var_label(df$age) <- "Age in years"

# Convert to factors
as_factor(x)
as_factor(df)  # all labelled columns

# Remove labels
zap_labels(df)
zap_formats(df)
```

## Tagged NA (Stata/SPSS)

```r
# Create tagged NA
tagged_na("a")
tagged_na("b")

# Check
is_tagged_na(x)
na_tag(x)
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.