'I can't seem to find a fix for the "ValueError: Unknown subheader signature" raised while reading sas file using pd.read_sas?

I am trying to load a sasbdat file in python using pd.read_sas() and I fail to load the data due to the below error.

ValueError                                Traceback (most recent call last)
<ipython-input-148-64f915da8256> in <module>
----> 1 df_sas = pd.read_sas('input_sasfile.sas7bdat', format='sas7bdat')

~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sasreader.py in read_sas(filepath_or_buffer, format, index, encoding, chunksize, iterator)
    121 
    122         reader = SAS7BDATReader(
--> 123             filepath_or_buffer, index=index, encoding=encoding, chunksize=chunksize
    124         )
    125     else:

~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in __init__(self, path_or_buf, index, convert_dates, blank_missing, chunksize, encoding, convert_text, convert_header_text)
    144 
    145         self._get_properties()
--> 146         self._parse_metadata()
    147 
    148     def column_data_lengths(self):

~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in _parse_metadata(self)
    349                 self.close()
    350                 raise ValueError("Failed to read a meta data page from the SAS file.")
--> 351             done = self._process_page_meta()
    352 
    353     def _process_page_meta(self):

~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in _process_page_meta(self)
    355         pt = [const.page_meta_type, const.page_amd_type] + const.page_mix_types
    356         if self._current_page_type in pt:
--> 357             self._process_page_metadata()
    358         is_data_page = self._current_page_type & const.page_data_type
    359         is_mix_page = self._current_page_type in const.page_mix_types

~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in _process_page_metadata(self)
    388             subheader_signature = self._read_subheader_signature(pointer.offset)
    389             subheader_index = self._get_subheader_index(
--> 390                 subheader_signature, pointer.compression, pointer.ptype
    391             )
    392             self._process_subheader(subheader_index, pointer)

~\.conda\envs\overloaded-new\lib\site-packages\pandas\io\sas\sas7bdat.py in _get_subheader_index(self, signature, compression, ptype)
    401             else:
    402                 self.close()
--> 403                 raise ValueError("Unknown subheader signature")
    404         return index
    405 

ValueError: Unknown subheader signature

Though I found relevant github issue (https://github.com/pandas-dev/pandas/issues/24794), but it was closed because the issue got resolved by updating the pandas.

Any help is greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source