Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Write DataFrame to SPSS .sav File in R

  • Last Updated : 14 Sep, 2021

In this article, we are going to see how to write Dataframe to SPSS .sav File in R Programming language. The SPSS Statistics File Format is a proprietary binary format, developed and maintained as the native format for the SPSS statistical software application. To write a data frame in SPSS format in R we use the write_sav() function of the haven package in R.

Syntax: write_sav(Data,”Filename.sav”)


  • Data: Dataframe that is been exported
  • Filename.sav: Filename where exported dataframe will be stored

Writing dataframe to SPSS .sav file

Here we are going to use the haven package, which is used to read write various data formats. 


# Create dataframe Demo
Demo <- data.frame(Batch = c(2017, 2018, 2019, 2020, 2021),
                  Students = c(2300, 1200, 3500, 1400, 120),
                  Class = c("DSA Essential", "Placement100",
                            "C++: Expert"
                            "Web Development Bootcamp",
                            "Android Development Bootcamp"))
# load haven package
# Write file using write_sav() function
write_sav(Demo, "SPSS.sav")


After running the code, we see a new file SPSSS.sav in your working directory.

Working directory

We can see data in SPSS.sav file using the following code:




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!