Skip to content

Fix COMP page trailer layout for SAS7BDAT files - #423

Open
hpoettker wants to merge 1 commit into
WizardMac:devfrom
hpoettker:write-compressed-sas-rows
Open

hpoettker wants to merge 1 commit into
WizardMac:devfrom
hpoettker:write-compressed-sas-rows

Conversation

@hpoettker

@hpoettker hpoettker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

SAS7BDAT files with row compression as currently written by ReadStat (with the default page size) are rejected by SAS with the error

ERROR: Page header information invalid for index_OBS_on

The problem is in the COMP page, which was good in 2d942c3 but #417 uncovered a missing condition on the page size.

SAS saves the offset of the COMP page trailer in a signed 16-bit field so it needs to get creative for page sizes of 32 KiB and above. This PR addresses this.

Validation

The change is built on inspection of both 64-bit and 32-bit data files with compressed rows and page sizes 8KB, 16KB, 31KB, 32KB, 64KB as generated by SAS.

I've written the same set of data files with ReadStat and the proposed change, and all produced data files were accepted by SAS.

Row-compressed files contain an extra page after the metadata (page
type 0x9000). The signed 16-bit field at phs-2 of this page holds the
offset to the page trailer. The writer had three problems here:

- It placed the trailer at the end of the physical page. For page
  sizes of 32 KiB and above the field overflowed (e.g. 0xFFBE for
  64 KiB pages). SAS then rejected the file with "Page header
  information invalid".
- The trailer offsets only matched SAS for 32-bit files.
- The field value only matched SAS for 64-bit files with pages below
  32 KiB.

The physical page size is unchanged. Beyond the trailer, the page is
zero-filled.
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.

1 participant