0

Assume the following:

I only have Python installed (and not SAS). I have an SAS table which I would like to work with in Python, this is easily done by loading a SAS table through pandas with:

pd.read_sas  # See the link: https://www.marsja.se/how-to-read-sas-files-in-python-with-pandas/

Now when I am done with my analysis, I would like to export my dataframe to an SAS table, is this possible? If I would like to export my dataframe to an CSV or EXCEL file then that is easy, but now I would like to export it to an SAS table.

Note, I know that for instance in latest version of VIYA you can write Python code directly in SAS, but the question here is: Can i export a dataframe to a SAS table similarly as I could export it to any other format such as CSV or Excel?

  • Per pandas [IO tools](https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html), there is no `to_sas` method. Please [research](https://meta.stackoverflow.com/q/261592/1422451) as there may be other Python libraries that can export to SAS formats. Do note: it is off-topic on StackOverflow to seek recommendation of books, tools, software libraries, etc. – Parfait Dec 29 '21 at 17:08
  • I don't know about python but R has haven if that's an option. – Reeza Dec 29 '21 at 23:34
  • The question [here](https://stackoverflow.com/q/49235845/13716967) and the selected answer should help – cookesd Dec 30 '21 at 03:43
  • I had seen that post @cookesd and it helped and since no other answer is available I assume the closest I can get is: https://pypi.org/project/xport/ . – MathStat2718 Dec 30 '21 at 09:45
  • I think the pyreadstat package is helpful. You can use write_xport method to export the dataframe into a XPT file which can be read into SAS easily. But this is not useful for large dataset since this method is extremely inefficent in the usage of storage space. https://github.com/Roche/pyreadstat – Doraelee Jul 10 '23 at 02:20

0 Answers0