Skip to content

SAS7BDAT file not readable #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yao-peng-build opened this issue Mar 24, 2025 · 6 comments
Open

SAS7BDAT file not readable #284

yao-peng-build opened this issue Mar 24, 2025 · 6 comments
Labels
bug Something isn't working requires changes in Readstat waiting for changes in the C library Readstat solved on dev

Comments

@yao-peng-build
Copy link

`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
Copy link
Author

pyreadstat version == 1.2.8

@yao-peng-build
Copy link
Author

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

@ofajardo ofajardo changed the title pyreadstat Bug SAS7BDAT file not readable May 12, 2025
@ofajardo
Copy link
Collaborator

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 ofajardo added bug Something isn't working to be reported in Readstat labels May 12, 2025
@ofajardo
Copy link
Collaborator

reported in WizardMac/ReadStat#336

@ofajardo ofajardo added requires changes in Readstat waiting for changes in the C library Readstat and removed to be reported in Readstat labels May 26, 2025
@ofajardo
Copy link
Collaborator

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.

@DanteDT
Copy link

DanteDT commented May 31, 2025

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 ..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working requires changes in Readstat waiting for changes in the C library Readstat solved on dev
Projects
None yet
Development

No branches or pull requests

3 participants