pyreadstat icon indicating copy to clipboard operation
pyreadstat copied to clipboard

SAS7BDAT file not readable

Open yao-peng-build opened this issue 11 months ago • 6 comments

`import pyreadstat

file_path = r"C:\Users\YaoPeng\AppData\Local\Temp\raw_data\ae.sas7bdat"

encodings = ["utf-8", "gbk", "gb2312", "cp1252", "latin1", "iso-8859-1", "utf-16"] for enc in encodings: try: df, meta = pyreadstat.read_sas7bdat(file_path, metadataonly=True) print("Metadata read successfully, column name:", meta.column_names) except Exception as e: print("Metadata read failure, error message:", str(e)) print(f"Encoding {enc} failed")`

ae.zip

Image

Hi! As shown in Figure 1, this is a sas7bdat data that I opened in variable view with the SAS System Viewer software, and I want to get this data, using python, Python 3.9.13,But running the appeal code results in an error,Error prompt :Metadata read failure, error message: Invalid file, or file has unsupported features,And attempts to implement multiple encoding formats have failed.However, I downloaded the official test file sample.sas7bdat from the git hub to run this code. So why is my own ae.sas7bdat file running this code error? In addition, their own ae.sas7bdat file can also be opened normally by SAS System Viewer software, but the official test file sample.sas7bdat cannot be opened normally by SAS System Viewer software.Tips as shown in Figure 2

Image

yao-peng-build avatar Mar 24 '25 03:03 yao-peng-build

pyreadstat version == 1.2.8

yao-peng-build avatar Mar 24 '25 05:03 yao-peng-build

Traceback (most recent call last): File "D:\python-testtest\main.py", line 6, in df, meta = pyreadstat.read_sas7bdat(file_path) File "pyreadstat\pyreadstat.pyx", line 129, in pyreadstat.pyreadstat.read_sas7bdat File "pyreadstat\_readstat_parser.pyx", line 1166, in pyreadstat._readstat_parser.run_conversion File "pyreadstat\_readstat_parser.pyx", line 908, in pyreadstat._readstat_parser.run_readstat_parser File "pyreadstat\_readstat_parser.pyx", line 830, in pyreadstat._readstat_parser.check_exit_status pyreadstat._readstat_parser.ReadstatError: Invalid file, or file has unsupported features

yao-peng-build avatar Mar 24 '25 05:03 yao-peng-build

thanks for the report. The problem seems to be coming from the underlaying C library Readstat. Feel free to report the issue there, it needs to be solved there first. It is unlikely that it is an encoding issue.

ofajardo avatar May 12 '25 13:05 ofajardo

reported in https://github.com/WizardMac/ReadStat/issues/336

ofajardo avatar May 26 '25 12:05 ofajardo

reading ae.sas7bdat solved on dev! feel free to test.

Regarding why sample.sas7bdat is not opening in your viewer, I don't know, that file was generated on SAS, so if it does not open, that is a problem beyond the scope of this project.

ofajardo avatar May 26 '25 14:05 ofajardo

Possibly related to this: https://pharmasug.org/proceedings/2018/EP/PharmaSUG-2018-EP08.pdf

"The first question to ask is why SAS System Viewers cannot open datasets generated in SAS 9.4 ..."

DanteDT avatar May 31 '25 15:05 DanteDT

solved on new version 1.3.0

ofajardo avatar Jun 27 '25 14:06 ofajardo