ARCHIVED: How do I import SPSS, Stata, or SAS data files in R?
To import SPSS, Stata, or SAS data files in R, first install and load
the package foreign
. The functions
read.spss()
, read.dta()
, and
read.xport()
of the package foreign
import
SPSS, Stata, and SAS Transport data files, respectively.
Use the following syntax to import the three types of data files:
> spssdata <- read.spss("C:/temp/spssfile.sav") > statadata <- read.dta("C:/temp/statafile.dta") > sasdata <- read.xport("C:/temp/sasfile.xpt")
The three data files are saved as R objects, called spssdata
,
statadata
, and sasdata
. The data sets are stored in
R's memory and can be called for statistical analysis during the
current R session.
Note: R cannot import SAS permanent data set
(.ssd
or .sas7bdat
) files. Use Stat/Transfer
to convert SAS permanent data set files to other file formats and then
import them to R. At Indiana University, the Stat/Transfer software is
available on Quarry and the Windows Student Technology Center (STC)
computers.
If you have questions about using statistical and mathematical software at Indiana University, contact the UITS Research Applications and Deep Learning team.
This is document azuw in the Knowledge Base.
Last modified on 2023-05-09 14:38:28.