{"id":7699,"library":"saspy","title":"SASPy (SAS Python Interface)","description":"SASPy is an open-source Python package that provides an interface to the SAS System, allowing Python programmers to leverage their licensed SAS infrastructure. It enables bi-directional data exchange between pandas DataFrames and SAS datasets, submission of SAS code, and access to SAS analytical capabilities like machine learning and econometrics. Currently at version 5.105.1, the library maintains an active release cadence with frequent updates addressing new features, enhancements, and bug fixes.","status":"active","version":"5.105.1","language":"python","source_language":"en","source_url":"https://github.com/sassoftware/saspy","tags":["SAS","data analytics","interoperability","data science","enterprise","dataframe","analytics"],"install":[{"cmd":"pip install saspy","lang":"bash","label":"PyPI"},{"cmd":"conda install -c conda-forge saspy","lang":"bash","label":"Conda-forge"}],"dependencies":[{"reason":"Extensive integration for data exchange with SAS datasets.","package":"pandas"},{"reason":"Required for IOM (Integrated Object Model) access method to connect to SAS.","package":"Java Development Kit (JDK)","optional":true},{"reason":"Required for Apache Arrow support and Arrow-based Parquet conversion (added in v5.105.0).","package":"pyarrow","optional":true}],"imports":[{"wrong":"import saspy\nsas = saspy.SASsession()","symbol":"SASsession","correct":"from saspy import SASsession"}],"quickstart":{"code":"import saspy\nimport pandas as pd\nimport os\n\n# NOTE: SASPy requires a configuration file (sascfg_personal.py) to define connection details.\n# This file is typically located in your Python site-packages/saspy directory or ~/.config/saspy/.\n# For example, using a 'winlocal' configuration (defined in sascfg_personal.py):\n# sas = saspy.SASsession(cfgname='winlocal')\n# If only one configuration is defined, or if running in an interactive environment that supports prompts:\nsas = saspy.SASsession()\n\nprint(f\"SAS Connection established: {sas.SASsessionid}\")\n\n# Example: Submit SAS code and get results\nresult = sas.submit(\"proc print data=sashelp.class(obs=5); run;\")\nprint(\"SAS Log:\\n\", result['LOG'])\nprint(\"SAS Listing:\\n\", result['LST'])\n\n# Example: Transfer a pandas DataFrame to SAS\ndata_df = pd.DataFrame({\n    'col1': [1, 2, 3],\n    'col2': ['A', 'B', 'C']\n})\n\nsas_data_obj = sas.dataframe2sasdata(data_df, 'WORK.mydata')\nprint(f\"DataFrame '{data_df.shape}' transferred to SAS library WORK as 'mydata'.\")\n\n# Example: Read SAS data back into a pandas DataFrame\nretrieved_df = sas.sasdata('mydata', libref='WORK').to_dataframe()\nprint(f\"Retrieved DataFrame head:\\n{retrieved_df.head()}\")\n\nsas.endsas()","lang":"python","description":"This quickstart demonstrates how to establish a connection to a SAS session, submit arbitrary SAS code, and exchange data between a pandas DataFrame and a SAS dataset. It highlights the importance of the `sascfg_personal.py` configuration file for defining SAS connection details."},"warnings":[{"fix":"Upgrade SASPy to version 5.104.1 or newer. If upgrading is not possible, ensure dataframes passed to `dataframe2sasdata` have `None` values converted to empty strings or other non-NaN representations.","message":"With Pandas 3.0.0, a change was made to store `None` as `NaN`, which caused `dataframe2sasdata` to throw exceptions. This was fixed in SASPy v5.104.1.","severity":"breaking","affected_versions":"pandas 3.0.0, saspy < 5.104.1"},{"fix":"Always copy `sascfg.py` to `sascfg_personal.py` and place your configurations in the `_personal` file. This file will not be overwritten by upgrades. The file can be located in your Python site-packages/saspy directory or in `~/.config/saspy/`.","message":"SASPy relies on `sascfg_personal.py` for connection configurations. If you modify the original `sascfg.py` instead of creating `sascfg_personal.py`, your configurations might be overwritten during a SASPy upgrade.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid using `proc printto` in SAS code submitted via SASPy, or ensure `proc printto; run;` is used to revert log/listing redirection *before* any SASPy methods that require log access.","message":"Using `proc printto` in submitted SAS code to redirect the SAS Log or Listing can cause SASPy to hang, fail, or not return results, as SASPy parses the log for operational information.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Exercise caution with `ABORT` statements. If necessary, ensure they are handled within the SAS session logic to prevent termination if possible, or gracefully handle connection loss in Python.","message":"SAS `ABORT` statements (e.g., `%abort`, `data _null_; abort;`) can unexpectedly terminate the connected SAS session, breaking the SASPy connection and leading to further errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'5.105.1':61 'access':48 'activ':66 'address':72 'allow':21 'analyt':51,81,87 'bi':33 'bi-direct':32 'bug':77 'cadenc':68 'capabl':52 'code':46 'current':58 'data':35,80,83 'datafram':39,86 'dataset':42 'direct':34 'econometr':57 'enabl':31 'enhanc':75 'enterpris':85 'exchang':36 'featur':74 'fix':78 'frequent':70 'infrastructur':29 'interfac':4,16 'interoper':82 'learn':55 'leverag':25 'librari':63 'licens':27 'like':53 'machin':54 'maintain':64 'new':73 'open':9 'open-sourc':8 'packag':12 'panda':38 'programm':23 'provid':14 'python':3,11,22 'releas':67 'sas':2,19,28,41,45,50,79 'saspi':1,5 'scienc':84 'sourc':10 'submiss':43 'system':20 'updat':71 'version':60","created_at":"2026-04-16T14:09:36.120662+00:00","updated_at":"2026-04-16T14:09:36.120662+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"5.107.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/sassoftware/saspy","docs":null,"changelog":null,"pypi":"https://pypi.org/project/saspy/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml","database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":null}}