Skip to content

Is there any plan to support direct writing to sas7bdat files? #205

Closed

Description

@want-fly
No description provided.

Activity

  1. ofajardo commented on Jul 25, 2022

    @ofajardo
    Collaborator

    Readstat does write sas7bdat files, but those files cannot be opened in SAS. WizardMac/ReadStat#98

    Until that issue is solved, there will be no supoort for this feature in pyreadstat

  2. hpoettker commented on Oct 20, 2026

    @hpoettker
    Contributor

    I think this issue can be re-opened.

    This PR in ReadStat seems to have achieved the last step: WizardMac/ReadStat#398

    I've round-tripped some SAS sample files with ReadStat. And it's looking very good!

  3. ofajardo commented on Oct 20, 2026

    @ofajardo
    Collaborator

    Awesome news! Thanks a lot for bringing this up!

  4. ofajardo commented on Oct 25, 2026

    @ofajardo
    Collaborator

    @hpoettker I have added write_sas7bdat . It would be nice if people could test. Particularly confirming that it can be opened in SAS. Also if suggestions on arguments that would make sense.
    Another thing I noticed when updating Readstat is that now for Xport date formats are read with a ending dot (like YYMMDD.), but I think for sas7bdat it is still lacks the dot.

  5. hpoettker commented on Oct 26, 2026

    @hpoettker
    Contributor

    @ofajardo I've had a look so far at the 64bit output, and it looks promising. But there are some rough edges.

    I'm currently investigating 2 problems: Compression and formats. I optimistic that we can fix the format issue but less so about the compression issue.

    Compression

    The SAS data file is not readable with compression enabled. So this option should maybe be removed from the API.

    There is also the problem that SAS data files have three compression types: no compression, CHAR and BINARY while ReadStat only supports CHAR (or row) compression at the moment.

    If we get CHAR compression working in a way that produces readable SAS data files, we can then consider whether the API should accept a boolean value or rather an enum corresponding to readstat_compress_t. If we don't get it working we should for the moment just omit the compress option.

    Formats

    There is definitely an issue here. It works well if I write a SAS data file with format YYMMDD but not with YYMMDD10., which produces files that are unreadable with SAS.

    I'm optimistic that this can be fixed. I'll investigate and report back.

  6. ofajardo commented on Oct 26, 2026

    @ofajardo
    Collaborator

    hi @hpoettker thanks for looking into this!. Regarding compression, I agree, we can just remove the argument until it is usable in the future. If one of the compression works then I would add an argument that accepts all compressions, but fails immediately for those not supported, so that in the future we do not need to change the name or signature of the argument.

    For Formats: if you use YYMMDD10 (withouth end dot) does it work? I am asking because when using read_sas7bdat we get YYMMDD10 if I am not mistaken, so it would make sense that for writing it has to be also without the dot. The not so nice thing here is that for XPORT the latest changes include the end dot for both reading and writing, so now sas7bdat and xport behave differently.

  7. hpoettker commented on Oct 26, 2026

    @hpoettker
    Contributor

    There are two problems with the formats.

    One problem is that the reader does not produce the expected format names (including the final .).

    The other problem is that for a format like DOLLAR12.2 the information in the data file is split into DOLLAR, 12, and 2 and needs to be written into different places. But ReadStat currently just writes DOLLAR12.2 where only DOLLAR is expected.

    Expect some PRs in ReadStat soon.

  8. ofajardo commented on Oct 26, 2026

    @ofajardo
    Collaborator

    Ok cool, please let me know here when ready so that I refresh the Resdstat sources on dev

  9. hpoettker commented on Oct 26, 2026

    @hpoettker
    Contributor

    @ofajardo Your intuition about the difference between YYMMDD10 and YYMMDD10. was exactly right.

    If WizardMac/ReadStat#419 is merged, the write API will accept both and the reader will return YYMMDD10. in both cases.

    Based on my current testing, the change is good to go if the reference PR is merged, and we keep to 64bit uncompressed files, which would mean removing the is_64bit and the compress parameter from write_sas7bdat.

    I plan to have a look at both compression and 32bit files but I won't make any promises about it. I would declare the two topics out of scope of this issue and open up a new one for them.

  10. ofajardo commented on Oct 27, 2026

    @ofajardo
    Collaborator

    Sounds good ... excellent actually, this feature has being waited for years thanks!
    I will update Resdstat sources as soon as they merge your PR and remove the compression and 32 bits arguments here. Let me know in case you have more suggestions.

  11. 5 remaining items

  12. hpoettker commented on Nov 1, 2026

    @hpoettker
    Contributor

    The PRs for the row compression WizardMac/ReadStat#423 and the alignment of format names between sas7bdat and sas7bcat WizardMac/ReadStat#424 are now merged in ReadStat.

    My bug list regarding write_sas7bdat is now empty, and it should be possible to add a compression argument to write_sas7bdat.

    I've tested the bug fixes so far mostly individually. I'll try to do some integrated testing of write_sas7bdat in the upcoming week and let you know whether I've found anything else.

  13. ofajardo commented on Nov 2, 2026

    @ofajardo
    Collaborator

    hi @hpoettker, thanks a lot! I have updated the Readstat sources. I also added an argument row_compress for write_sas7bdat. I am mimicking what I did for write_sav where I have row_compress for row compression and compress for binary compression. The other option would be to have a single argument with and make it fail if the users try to do binary compression.

  14. hpoettker commented on Nov 10, 2026

    @hpoettker
    Contributor

    I had previously only tested with small files and now switched to larger files for the final testing. That turned out to be quite productive. 😄

    We need a lot more changes in ReadStat: WizardMac/ReadStat#432

    I'll let you know when the PR is merged. But after that the write feature should be good to go.

  15. hpoettker commented on Nov 10, 2026

    @hpoettker
    Contributor

    WizardMac/ReadStat#432 is now merged. 🚀

  16. ofajardo commented on Nov 11, 2026

    @ofajardo
    Collaborator

    hi @hpoettker thanks a lot for the thorough testing and PRs to Readstat! the most recent changes from Readstat are now in dev!

  17. hpoettker commented on Nov 11, 2026

    @hpoettker
    Contributor

    Thanks for updating dev!

    We might get to revisit the API topic around row (RLE) and binary (RDC) compression. 😄

    I've opened WizardMac/ReadStat#433 to add the binary compression to the writer.

  18. hpoettker commented on Nov 11, 2026

    @hpoettker
    Contributor

    WizardMac/ReadStat#433 is now merged!

    Compression is no longer a binary issue when writing sas7bdat files. 😄

  19. ofajardo commented on Nov 12, 2026

    @ofajardo
    Collaborator

    Dev is updated with the latest Resdstat sources and binary compression is exposed as an argument (compress)

  20. hpoettker commented on Nov 12, 2026

    @hpoettker
    Contributor

    Thanks! I tested the latest commit, and produced my sample files. SAS is happy with them!

    I'd say that the issue can be closed. 🚀

  21. ofajardo commented on Nov 13, 2026

    @ofajardo
    Collaborator

    great news! Is there any other important feature/fix coming soon to Readstat from your side that would be good to get in before doing a release? Otherwise I would do a release soon.

  22. hpoettker commented on Nov 13, 2026

    @hpoettker
    Contributor

    I've opened one more pull request. But it's about a separate niche issue and currently waiting for feedback from the person who raised the issue some time ago. I wouldn't wait for that to be merged.

    I have no other things currently planned for ReadStat. So a release would be great!

  23. ofajardo commented on Nov 14, 2026

    @ofajardo
    Collaborator

    Released! Thanks a lot for solving this issue hanging for years!

  24. hpoettker commented on Nov 14, 2026

    @hpoettker
    Contributor

    Thanks for the release!

    Solving this issue was really a collaborative effort. I only built on the foundations that were laid by @evanmiller by his great work on ReadStat overall and WizardMac/ReadStat@2d942c3 in particular, and by @hadley with WizardMac/ReadStat#398, which cleared the last road block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementrequires changes in Readstatsolved on dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions