Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Import SAS Files into R?

  • Last Updated : 04 Jan, 2022

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 standard ASCII text 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
Recommended Articles
Page :

Start Your Coding Journey Now!