Skip to content

Latest commit

 

History

History
94 lines (63 loc) · 4.12 KB

File metadata and controls

94 lines (63 loc) · 4.12 KB

readstat

Convert SAS (.sas7bdat, .xpt), Stata (.dta) & SPSS (.sav, .zsav, .por) files to CSV, preserving the underlying codes of labelled values by default. Also dumps the rich variable metadata these formats carry - variable labels, value labels, missing-value codes, measure & display settings - with --metadata. Only SPSS portable (.por) files are read whole - every other format streams with constant memory.

Table of Contents | Source: src/cmd/readstat.rs | 🤯🐻‍❄️🚀

Description | Usage | Readstat Options | Common Options

Description ↩

Convert SAS, Stata & SPSS files to CSV.

EXPERIMENTAL: the readers this command is built on are young. Spot-check the output against your source files before relying on a conversion, and please report anything that looks wrong.

Supported input formats:

SAS     .sas7bdat, .xpt, .xpt5, .xpt8
Stata   .dta
SPSS    .sav, .zsav, .por

Coded values are written as their underlying codes, not their labels, so the conversion is lossless. Use --value-labels to decode them instead.

The variable metadata these formats carry - variable labels, value labels, missing-value codes, measure & display settings - can be dumped instead of the data with --metadata.

Convert a SAS dataset to CSV:

qsv readstat data.sas7bdat > data.csv

Convert an SPSS file, decoding coded values to their labels:

qsv readstat --value-labels survey.sav -o survey.csv

Dump the variable dictionary of a Stata file:

qsv readstat --metadata pretty-json panel.dta

Pipe straight into another qsv command:

qsv readstat data.sas7bdat | qsv stats

For examples, see https://github.com/dathere/qsv/blob/master/tests/test_readstat.rs.

Usage ↩

qsv readstat [options] [<input>]
qsv readstat --help

Readstat Options ↩

     Option      Type Description Default
 ‑‑metadata  string Dump variable metadata instead of the data. Valid values: none, csv, json, pretty-json. none
 ‑‑value‑labels  flag Decode coded values to their label strings (e.g. 1 becomes "Male") instead of writing the underlying codes. Stata & SPSS only - SAS keeps its value labels in a separate .sas7bcat catalog, which this command does not read yet.
 ‑j,
‑‑jobs 
integer Number of reader threads. Raising it speeds up large uncompressed files at the cost of memory, as out-of-order chunks have to be buffered to keep the rows in source order. Row order is preserved either way. 1
 ‑b,
‑‑batch 
integer Number of rows to read into memory at a time. Does not apply to SPSS portable (.por) files - they have no chunked reader upstream, so they are read whole & memory scales with the file. 50000

Common Options ↩

     Option      Type Description Default
 ‑h,
‑‑help 
flag Display this message
 ‑o,
‑‑output 
string Write output to instead of stdout.
 ‑d,
‑‑delimiter 
string The delimiter to use when writing CSV data. Must be a single character. ,

Source: src/cmd/readstat.rs | Table of Contents | README