Import/Read SAS dataset into R

This post is part of 'SASnR | Reading data' series

In this post, we will see how to import/read a sas dataset into R session.

Haven package enables R to read and write various data formats used by other statistical packages, including SAS.

In order to import a SAS dataset into R, we can use the below R code.


Things to note:

  • On line 1 of the above code, we are installing the haven package. It is a one-time activity after installation of R
  • On line 2, we are indicating that the package haven has to be attached and loaded
  • On line 3, we are indicating that a "tibble" (dataset) named "class" has to be created by reading the specified sas dataset using "read_sas" function of haven package.
  • On line 3, please note that in the folderpath, forward slash has to be used as delimiter instead of backslash when working in windows environment.
  • On line 3, notice that we need to specify both the name of SAS dataset and file extension


Example class dataset (sas dataset) can be downloaded from here.

Post categories