xportrs
SAS Transport (XPT) V5/V8 format reader and writer in pure Rust.
Features
- Full V5 format support - Maximum compatibility with regulatory submission systems
- V8 format support - Extended limits for variable names (32 chars), labels (256 chars)
- IEEE ↔ IBM float conversion - Accurate floating-point conversion between formats
- All 28 SAS missing value codes - Standard (
.) and special (.A-.Z,._) - Streaming API - Memory-efficient processing of large files
- Optional Polars integration - Direct DataFrame conversion with
polarsfeature
Installation
Or add to your Cargo.toml:
[]
= "0.0.1"
Optional Features
# Enable Polars DataFrame integration
= { = "0.0.1", = ["polars"] }
# Enable Serde serialization
= { = "0.0.1", = ["serde"] }
Format Comparison
| Feature | V5 Limit | V8 Limit |
|---|---|---|
| Variable name | 8 chars | 32 chars |
| Variable label | 40 chars | 256 chars |
| Format name | 8 chars | 32 chars |
| Dataset name | 8 chars | 32 chars |
Usage
Reading XPT Files
use Path;
use ;
// Read entire dataset
let dataset = read_xpt ?;
println!;
// Access columns
for column in & dataset.columns
Writing XPT Files
use Path;
use ;
// Create dataset with columns
let mut dataset = with_columns;
// Add rows
dataset.add_row;
// Write to file
write_xpt ?;
Streaming Large Files
use Path;
use read_xpt_streaming;
// Process rows one at a time (memory efficient)
let reader = read_xpt_streaming ?;
for observation in reader
Missing Values
SAS supports 28 different missing value codes:
use ;
// Standard missing (.)
let missing = numeric_missing;
// Special missing (.A through .Z)
let missing_a = numeric_missing_with;
// Check for missing
assert!;
Polars Integration
Enable the polars feature for DataFrame support:
[]
= { = "0.0.1", = ["polars"] }
use Path;
use ;
// Read XPT to DataFrame
let df = read_xpt_to_dataframe ?;
// Write DataFrame to XPT
write_dataframe_to_xpt ?;
V8 Format
By default, files are written in V5 format. Use XptWriterOptions for V8:
use Path;
use ;
let options = default .with_version;
write_xpt_with_options ?;
MSRV
The minimum supported Rust version is 1.92.
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Related Projects
This crate is used by Trial Submission Studio, a desktop application for transforming clinical trial data into FDA-compliant CDISC formats.