Open XPT File with R

From PHUSE Wiki
Jump to: navigation, search

This page describes how to open XPT files (aka SAS Transport v5 files as commonly used in CDISC datasets) using R packages.

See also:


Generally, in order to use XPT files, organizations will employ SAS, as it has native handling for them. However, not everyone has SAS. Or maybe the type of person who needs to work with the files wouldn't otherwise need a SAS license.

One option is to download and use the free Universal Xpt File Viewer. This was previously known as the SAS Viewer, so if you have the SAS Viewer tool, that works in the same way. This is free, and easily accessible; however, it is very limited in features and not suited to automated handling of files.

The steps below guide you through how to open XPT files using R, a collection of free, open source statistical packages.


  1. Download and install the windows binary from the R Project site
  2. Launch R and from the Packages menu select install to download and install these two packages
    1. Hmisc
    2. SASxport
  3. Set the current directory to the directory containing the *.xpt file: (File -> Change dir …)
  4. Issue these commands (sample uses bw.xpt; sub in whatever your file is named):
    1. library(SASxport)
    2. data(Alfalfa)
    3. lookup.xport("bw.xpt")
    4. Alfalfa <- read.xport("bw.xpt")
    5. head (Alfalfa)

Last revision by Angusmdmclean, 2017-01-7