3

I would like to know if there's any python library that supports this conversion, currently the options i've found are SASpy, csv or SQL database but was unsuccessful. This is not really a programming question but hope it won't be an issue. I've found this post: Export pandas dataframe to SAS sas7bdat format But was hoping to find any updates on new libraries that support sas7bdat files creation and how licensing works for SASpy.

Z3KR0W
  • 31
  • 2
  • This is already answered here - https://stackoverflow.com/questions/49235845/export-pandas-dataframe-to-sas-sas7bdat-format – Mortz Oct 17 '22 at 09:29
  • 1
    Does this answer your question? [Export pandas dataframe to SAS sas7bdat format](https://stackoverflow.com/questions/49235845/export-pandas-dataframe-to-sas-sas7bdat-format) – Mortz Oct 17 '22 at 09:29
  • I've read the post yes, but unfortunately as it says "some have reverse engineered enough of it to read at least, but from what I've seen no good SAS7BDAT writer exists" so I was hoping to find a updates on that matter or how does SAS license work since is my first time interacting with it. – Z3KR0W Oct 17 '22 at 09:37
  • I would consider writing to another format that SAS supports if you're trying to transport a file somewhere. – Stu Sztukowski Oct 17 '22 at 14:30
  • The answer is currently the same, SAS7BDAT is a proprietary format and there are not open source writing tools. However, the XPORT file format which can be read by SAS and converts data to a SAS dataset is open and you can use that format instead. – Reeza Oct 17 '22 at 17:22

2 Answers2

3

The sas7bdat is very hard to write. The read is fairly doable (but pretty hard) but the write is brutal. SAS costs a LOT of money and cannot be purchased (it is leased). My suggestions:

  • Use one of the products by companies that have done it. Some examples: CoyRoc (SSIS adaptor) $, StatTransfer $, SPSS $$$, SAS (lots of dollar signs). WPS might be able to do it but they save to their format to avoid the mess. They probably also support sas7bdat export.

  • Do not use sas7bdat format. Consider something else like SAS Transport format. Look at my github repository (savian-net) for C# code that can do it. Translate to Python or find a python library that can handle SAS Transport.

The sas7bdat is a binary, proprietary protocol that is 100% not published anywhere. Any docs are guesses based upon binary sleuthing. It is based on an old mainframe format and 'likely remnants' appear to be included. My suggestion is to avoid it like the plague and find an alternative.

AlanC
  • 529
  • 3
  • 7
1

An alternative to using xport as Stu suggested - as of Viya 2021.2.6, SAS supports reading externally generated parquet files via the new parquet import engine. As such, you could export the file to parquet via Python then directly import that into SAS and save it as a .sas7bdat file.

https://communities.sas.com/t5/SAS-Communities-Library/Parquet-Support-in-SAS-Compute-Server/ta-p/811733