Exporting Datasets to SPSS

Overview

All psych350data datasets can be exported as SPSS .sav files with full metadata. You do not need to prep or transform the data first — the export functions handle everything internally. Each export automatically:

  • Converts categorical variables from character strings to numeric codes
  • Adds value labels so SPSS displays category names in Data View
  • Adds variable labels describing each column in Variable View
  • Replaces NA with -99 and registers it as user-defined missing

Setup

library(psych350data)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

Quick Export

Each dataset has a dedicated export function that writes a .sav file:

# Export to current working directory (uses default filename)
export_superman_sav()

# Export to a specific location
export_football_sav("~/Desktop/football_data.sav")

Or use the generic export_sav() function with a dataset name:

export_sav("superman", path = "superman_data.sav")
export_sav("hotones")

All Export Functions

Function Default filename
export_superman_sav() superman_data.sav
export_superman_smes_sav() superman_smes_data.sav
export_superman_movies_sav() superman_movies_data.sav
export_superman_combined_sav() superman_combined_data.sav
export_hotones_sav() hotones_data.sav
export_hotones_sauces_sav() hotones_sauces_data.sav
export_hotones_episodes_sav() hotones_episodes_data.sav
export_tip_jokes_sav() tip_jokes_data.sav
export_mcu_sav() mcu_data.sav
export_mock_jury_sav() mock_jury_data.sav
export_candy_sav() candy_data.sav
export_candy_simple_sav() candy_simple_data.sav
export_football_sav() football_data.sav
export_huskers_sav() huskers_data.sav
export_cheese_sav() cheese_data.sav
export_lpd_sav() lpd_data.sav
export_parent_child_sav() parent_child_data.sav
export_hindsight_mg_sav() hindsight_mg_data.sav
export_hindsight_wg_sav() hindsight_wg_data.sav
export_interpersonal_sav() interpersonal_data.sav
export_selfdescriptive_sav() selfdescriptive_data.sav

Exporting for Answer Keys vs. Student Data

A common instructor workflow is to export the full dataset as an answer key and a subset of variables as the version students receive.

Full Dataset (Answer Key)

The default export includes every variable with all labels:

# Full dataset — all variables, all labels, -99 for missing
export_superman_sav("superman_answer_key.sav")
export_interpersonal_sav("interpersonal_answer_key.sav")

Subset of Variables (Student Version)

Use dplyr::select() to choose only the variables students need, then pipe the result to export_sav(). All available labels are automatically preserved for the selected variables:

# Superman — only the variables needed for a specific lab
superman |>
  select(num, media, type, clark_height, rt_critics_score) |>
  export_sav(path = "superman_student.sav")

# Interpersonal survey — just demographics and a few scales
interpersonal_data |>
  select(age, gender, race, gcb, risc, lsas) |>
  export_sav(path = "interpersonal_student.sav")

# Huskers — select with tidyselect helpers
huskers |>
  select(date, season, opp, result, starts_with("ne_")) |>
  export_sav(path = "huskers_nebraska_stats.sav")
Tip

When you pipe a data frame directly to export_sav(), it still replaces NA with -99 and declares -99 as user-missing for all numeric columns. Variable labels and value labels are applied for any columns that have them defined in the package’s internal label functions.

Export All Datasets at Once

To create .sav files for every dataset in the package:

export_all_sav(dir = "~/Desktop/PSYC350_SPSS/")

This creates one .sav file per dataset in the specified folder, using the default filenames. The folder is created if it doesn’t exist.

What Gets Converted During Export

Categorical Variables

In R, categorical variables are human-readable character strings:

superman |>
  select(num, media, type, age_grp) |>
  head(3)
#> # A tibble: 3 × 4
#>     num media               type    age_grp
#>   <int> <chr>               <chr>   <chr>  
#> 1     1 Superman            Film    Average
#> 2     2 Superman: The Movie Film    Average
#> 3     3 Smallville          TV Show Minimal

In the exported SPSS file, these become numeric codes with value labels:

Variable R value SPSS code SPSS value label
type "Film" 1 Film
type "TV Series" 2 TV Series
type "Serial" 3 Serial
age_grp "Minimal" 1 Minimal (<2 years)
age_grp "Average" 2 Average (2–5 years)
age_grp "Big" 3 Big (>5 years)

Missing Values

In R, missing values are NA:

superman |>
  select(num, media, ldb_scores) |>
  filter(is.na(ldb_scores))
#> # A tibble: 6 × 3
#>     num media                                        ldb_scores
#>   <int> <chr>                                             <dbl>
#> 1     3 Smallville                                           NA
#> 2     7 Superman                                             NA
#> 3     8 Superman & Lois                                      NA
#> 4     9 Lois & Clark: The New Adventures of Superman         NA
#> 5    10 The Adventures of Superboy                           NA
#> 6    11 The Adventures of Superboy                           NA

In the exported SPSS file, these become -99 with the missing value attribute set, so SPSS automatically excludes them from analyses — no manual setup needed.

Variable Labels

Every variable gets a descriptive label visible in SPSS Variable View. For example:

Variable SPSS variable label
clark_height Height of Clark Kent/Superman actor in meters
rt_critics_score Rotten Tomatoes critics score (0–100 scale)
age_grp Age difference category between Superman and Lois Lane actors

Controlling Missing Value Behavior

By default, NA values are converted to -99 with SPSS user-defined missing value codes. This is the standard behavior expected for PSYC 350 labs.

If you instead want SPSS system-missing (. in SPSS, which is the equivalent of NA), set use_sentinel = FALSE:

export_superman_sav("superman_sysmis.sav", use_sentinel = FALSE)
export_sav("superman", path = "superman_sysmis.sav", use_sentinel = FALSE)
Note

System-missing is how SPSS represents truly blank/unknown values. User-defined missing (-99) is a specific number that SPSS is told to treat as missing. Both are excluded from analyses, but -99 is more common in psychology lab settings because it makes it visually obvious that a value is missing when scrolling through Data View.

Auditing an Export

After exporting, use check_sav_export() to verify that labels and missing values are correctly applied:

export_huskers_sav("huskers_data.sav")
check_sav_export("huskers_data.sav")

This prints a summary report flagging any issues — for example, variables with missing variable labels or -99 values that aren’t declared as user-missing.

To see details for every variable (not just those with issues):

check_sav_export("huskers_data.sav", show_all = TRUE)

Reading an Exported File Back into R

If you need to read an exported .sav file back into R — for example, to verify what students will see — use get_spss_data():

huskers_clean <- get_spss_data("huskers_data.sav")

This reads the .sav file, converts -99 back to NA, and removes all SPSS labels, giving you a clean tibble ready for R analysis.

Tips for Instructors

Here’s a practical workflow for preparing lab materials:

  1. Generate the answer key by exporting the full dataset:
export_football_sav("football_answer_key.sav")
  1. Generate the student file by selecting only the variables students need:
football |>
  select(group, volume) |>
  export_sav(path = "football_student.sav")
  1. Verify both files to make sure labels and missing values look correct:
check_sav_export("football_answer_key.sav", show_all = TRUE)
check_sav_export("football_student.sav", show_all = TRUE)
  1. Distribute the student .sav file through Canvas or your LMS. Students can open it in SPSS (or JASP) and the value labels, variable labels, and missing value definitions are all pre-configured — no manual data setup required.

Using Exported Files in SPSS

After opening the .sav file in SPSS:

  1. Check Variable View to see all variable labels and value labels
  2. Toggle “Value Labels” in the toolbar (or View → Value Labels) to see category names instead of numeric codes in Data View
  3. Missing values are pre-configured — SPSS will automatically exclude -99 values from all analyses without any manual setup
  4. Re-export anytime from R if you need to update the data or change which variables are included