Table of Contents
The process of importing SAS files into R involves several steps that must be followed in order to successfully transfer the data. Firstly, the SAS file must be converted into a CSV format, which can be done using the “export” function in SAS. Once the file is in CSV format, it can be easily imported into R using the “read.csv()” function. Another option is to use the “foreign” package in R, which has a function specifically designed for importing SAS files. This package can be installed and loaded into R using the “install.packages()” and “library()” functions respectively. Once the package is loaded, the “read.ssd()” function can be used to directly import the SAS file into R. It is important to make sure that the file path is correctly specified in the function. By following these steps, users can successfully import SAS files into R for further analysis and manipulation.
Import SAS Files into R (Step-by-Step)
The easiest way to import SAS files into R is to use the read_sas() function from the library.
This function uses the following basic syntax:
data <- read_sas('C:/Users/User_Name/file_name.sas7bdat')The following step-by-step example shows how to import a SAS file into R in practice.
Step 1: Download a SAS Data File
For this example, we’ll download the SAS file called cola.sas7bdat from .

Step 2: Install haven Package
Next, we’ll install the haven package in R:
install.packages('haven')We’ll then load the package:
library(haven)Step 3: Import the SAS File
Next, we’ll use the read_sas() function to import the SAS file:
data <- read_sas('C:/Users/bob/Downloads/cola.sas7bdat')Once we’ve imported the SAS file, we can get a quick summary of the data:
#view class of data
class(data)
[1] "tbl_df" "tbl" "data.frame"
#display dimensions of data frame
dim(data)
[1] 5466 5
#view first six rows of data
head(data)
ID CHOICE PRICE FEATURE DISPLAY
1 1 0 1.79 0 0
2 1 0 1.79 0 0
3 1 1 1.79 0 0
4 2 0 1.79 0 0
5 2 0 1.79 0 0
6 2 1 0.890 1 1
The following tutorials explain how to import other file types into R:
Cite this article
stats writer (2024). How can I import SAS files into R using a step-by-step process?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-import-sas-files-into-r-using-a-step-by-step-process/
stats writer. "How can I import SAS files into R using a step-by-step process?." PSYCHOLOGICAL SCALES, 4 May. 2024, https://scales.arabpsychology.com/stats/how-can-i-import-sas-files-into-r-using-a-step-by-step-process/.
stats writer. "How can I import SAS files into R using a step-by-step process?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-import-sas-files-into-r-using-a-step-by-step-process/.
stats writer (2024) 'How can I import SAS files into R using a step-by-step process?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-import-sas-files-into-r-using-a-step-by-step-process/.
[1] stats writer, "How can I import SAS files into R using a step-by-step process?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, May, 2024.
stats writer. How can I import SAS files into R using a step-by-step process?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
