Skip to content

Instantly share code, notes, and snippets.

@jamespaultg
Created March 17, 2021 14:49
Show Gist options
  • Save jamespaultg/9b5e312b135372b4f50ab46acf4e9b6b to your computer and use it in GitHub Desktop.
Save jamespaultg/9b5e312b135372b4f50ab46acf4e9b6b to your computer and use it in GitHub Desktop.
Convert SPSS files to CSV using R
library(foreign)
# Converting one SPSS file
data <- read.spss("File_path_SPSS.sav",
reencode='utf-8',
use.value.labels = FALSE,
to.data.frame = TRUE)
head(data)
View(data)
write.csv2(data,"C:/Users/LYCJPG1/Documents/survey_results.csv")
# Converting many SPSS file in a folder
spss2csv <- function(filename) {
data <- read.spss(filename,
reencode='utf-8',
use.value.labels = FALSE,
to.data.frame = TRUE)
outputcsv <- paste0(filename,".csv")
write.csv2(data,outputcsv)
}
files <- list.files("Path where the SPSS files are present",
pattern="*.sav", full.names = TRUE)
lapply(files, spss2csv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment