Skip to content
Related Articles
Open in App
Not now

Related Articles

How to Import SAS Files into R?

Improve Article
Save Article
  • Last Updated : 02 Feb, 2023
Improve Article
Save Article

In this article, we are going to see how to import SAS files(.sas7bdat) into R Programming Language. 

SAS stands for Statistical Analysis Software, it contains SAS program code saved in a propriety binary format. The R packages discussed, haven and sas7bdat, involved reverse engineering this propriety format.

Used File: Click

Method 1: Using haven Package

Here we will use the haven package to import the SAS files. 

To install the package:

install.packages('haven')

To import the SAS file read_sas() methods are capable to read the file.

Syntax: 

read_sas(‘file’)

Example: Reading SAS file

R




# import lib
library(haven)
 
# import data
data <- read_sas('lond_small.sas7bdat')
 
# display data
data


Output:

Method 2: Using sas7bdat Package

Here we will use sas7bdat package to import the SAS files.

To install the package:

install.packages('sas7bdat')

To import the SAS file read_sas() methods are capable to read the file.

Syntax: 

read_sas7bdat(‘file’)

Example: Reading SAS file

R




# import lib
library(sas7bdat)
 
# import data
data <- read_sas7bdat('lond_small.sas7bdat')
 
# display data
data


Output:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!