xpt.rs
Rust library and CLI tool to read XPT v5 - SAS Transport files
Overview
xpttools (github: xpt.rs) is a Rust library and command-line tool suite for reading and working with SAS XPORT (XPT) version 5 files. These files are the standard format for data exchange in clinical research and are essential for regulatory submissions to agencies like the FDA.
Features
- Library: Use as a Rust crate in your projects for programmatic access to XPT files
- CLI Tool: Command-line utilities for inspection and conversion of XPT files
- Multiple Tools: Includes
xptcols,xpthead, andxpt2csvfor various operations - Cross-platform: Works on macOS, Windows, and Linux
- Standards Compliant: Implements TS-140 specification for SAS Transport format
CLI Tools
The xpttools suite includes three main command-line utilities:
xptcols: Print dataset metadata (variables, types, lengths, positions)xpthead: Display the first n rows of a datasetxpt2csv: Convert an XPT dataset to CSV format
CLI Usage Examples
Show column metadata
./target/release/xpttools xptcols DM.xptShow first 10 rows (default)
./target/release/xpttools xpthead DM.xptShow first 20 rows
./target/release/xpttools xpthead DM.xpt -n 20Convert a dataset (first member) to CSV
./target/release/xpttools xpt2csv PC.xpt -o PC.csvConvert a named member (if multiple)
./target/release/xpttools xpt2csv SDTM.xpt -d PC -o PC.csvShow first 10 rows of a specific dataset
./target/release/xpttools xpthead SDTM.xpt -d PCShow first 5 rows of a specific dataset
./target/release/xpttools xpthead SDTM.xpt -d PC -n 5Library Usage
Use xpt.rs as a Rust crate in your projects. For detailed library documentation and examples, see the USAGE.md documentation.
Quick Start - Reading from File
use xpttools::read_xpt_v5;
let datasets = read_xpt_v5("data.xpt")?;
let dataset = &datasets[0];
println!("Dataset: {} ({} variables, {} rows)",
dataset.name, dataset.vars.len(), dataset.rows.len());Reading from Bytes (for Tauri/web contexts)
use xpttools::read_xpt_v5_from_bytes;
let data = std::fs::read("data.xpt")?;
let datasets = read_xpt_v5_from_bytes(&data)?;Technical Notes
- TS-140 Specification: Implements the official Record Layout of a SAS Version 5/6 Data Set in SAS Transport (XPORT) Format, including NAMESTR offsets, headers, and missing value rules
- IBM Hex Floating-Point: Correctly handles IBM/360 Hex Floating-Point format conversion to IEEE-754, including proper exponent bias handling
- Standards Compliance: The code implements the 80-byte card stream, NAMESTR (140-byte) layout, and IBM/360 (HFP) → IEEE-754 conversion, matching the SAS specification exactly
Use Cases
Data Inspection
Quickly inspect XPT file structure and contents without SAS software
Data Conversion
Convert XPT files to CSV for use in other tools and workflows
Integration
Integrate XPT file reading into Rust applications and web services
Automation
Automate XPT file processing in CI/CD pipelines and data workflows