Problem with SAS file header being exactly 288 characters

Issue #4 resolved
Greg Sanders created an issue

The sas7bdat reader works great with sample files I've pulled from the internet. But it fails when we try to convert our own SAS files, apparently because it finds the file header is exactly 288 characters. This triggers an error at line 351. We first encountered this error on SAS files created on a Sun OS machine, but then tried to recreate the same SAS files on a Linux machine and got the same error.

Unfortunately I can't send the file because it's prohibited under the terms of our data sharing agreements with state government. But I wanted to raise this issue and see if others have reported this problem. Code:

        # Read the rest of the header
        hl = self.readVal('i', h, 196 + align1, 4)
        if u64:
            assert hl == 8192

(351) * h += f.read(hl - 288)

(note: hl is zero, upon returning from readVal() - so read(0) is invalid. )

ERROR: File "/projects/bigmatch/bigmatchgui/lib/sas7bdat_py3/sas7bdat.py", line 105, in init self.header = self._readHeader() File "/projects/bigmatch/bigmatchgui/lib/sas7bdat_py3/sas7bdat.py", line 351, in _readHeader h += f.read(hl - 288) ValueError: read length must be positive or -1

Comments (4)

  1. Jared Hobbs repo owner

    Unfortunately I don't have any sample files that exhibit this behavior so I'm unable to debug the issue. If you would be able to generate a test file with the header length that causes the problem and attach it to this ticket, that would be great.

  2. David Schatzel

    Hi Jared, I think I'm having a similar problem. I'm getting an error: "assert self.properties.header_length == 8192". I've attached a sample file "specialty.sas7bdat". Maybe this will help to debug the issue.

    Thanks! Dave

  3. Jared Hobbs repo owner

    @dschatzel thanks for the file. Relaxing the header length check seems to have fixed the problem so I committed the change and released version 2.0.2

  4. Log in to comment