Open In App

How to Import SAS Files into R?

Last Updated : 02 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads