Skip to content

add feature to read xpt / cport files - #446

Open
tbugfinder wants to merge 2 commits into
WizardMac:devfrom
tbugfinder:feature/cport-read
Open

tbugfinder wants to merge 2 commits into
WizardMac:devfrom
tbugfinder:feature/cport-read

Conversation

@tbugfinder

Copy link
Copy Markdown

This PR introduces the feature to read xpt - cport type of files.

closes: #187

tbugfinder and others added 2 commits November 30, 2026 14:32
SAS CPORT transport files (PROC CPORT) are often named .xpt, but are a
different, undocumented format, so readstat_parse_xport() failed on them
with a generic parse error. It now recognises them by their first record
(the "**COMPRESSED**" banner or "LIB CONTROL") and reads them with a new
reader in src/sas/readstat_cport_read.c:

- compressed and NOCOMPRESS files (blank/NUL run-length coding with 0xBC
  as the escape byte)
- the first dataset member of a library; catalog members are skipped
- variable names, labels, formats, informats, the dataset label and the
  row count from the member header
- values in the XPORT layout (IBM floats, special missing values)
- the session encoding (utf8, wlt1) when no input encoding is set

The layout was worked out from files written by SAS 9.4 (Windows, WLATIN1)
and SAS Viya 4 (Linux, UTF-8). Three of them are added to resources/ as
test files; the OS release field of cport_basic_win94.xpt, which held
stale bytes, was blanked. Further cases (catalogs, index and sort spans,
long labels, runs across records, truncated and corrupt files) are built
in memory by test_xport_cport().

Fixes WizardMac#187.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SAS CPORT files also turn up as .cpt or .cport. Read them through the
XPORT reader like .xpt files. They are input only: the output modules
still decide which extensions can be written, and the usage text, man
page and README list them as input formats only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Support for SAS CPORT Files

1 participant