Skip to content

Fix writing of SAS missing values - #416

Merged
evanmiller merged 1 commit into
WizardMac:devfrom
hpoettker:write-sas-missing-values
Oct 20, 2026
Merged

evanmiller merged 1 commit into
WizardMac:devfrom
hpoettker:write-sas-missing-values

Conversation

@hpoettker

Copy link
Copy Markdown
Contributor

ReadStat currently writes SAS numeric missing values (., ._, .A–.Z) to .sas7bdat files in a way SAS doesn't understand. The writer puts the inverted ASCII tag character into a standard quiet NaN (0x7FF8…), which isn't the NaN value that SAS actually expects as a basis.

The readstat CLI also drops tagged missing values when writing .sas7bdat: values are never passed to readstat_insert_tagged_missing_value.

Changes

  • src/sas/readstat_sas7bdat_write.c: missing values are now encoded the way SAS stores them:

    • The two most significant bytes are 0xFF 0xFF.
    • The third byte is the bitwise complement of the tag code: ._ → 0, . → 1, .A–.Z → 2–27.
    • All other bytes are zero.
    • The byte order follows the machine's endianness.
  • src/bin/write/mod_readstat.c: tagged missing values are now written through readstat_insert_tagged_missing_value when the output is .sas7bdat, as already done for .dta.

Verification

  • SAS-generated .sas7bdat files containing ., ._ and .A–.Z were converted with readstat in.sas7bdat out.sas7bdat. The output opens in SAS and shows the same missing values as the original. Before this change, none of the missing values survived.

@evanmiller
evanmiller merged commit cb66cfb into WizardMac:dev Oct 20, 2026
14 checks passed
@hpoettker
hpoettker deleted the write-sas-missing-values branch October 20, 2026 21:09
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.

2 participants