BookmarkSubscribeRSS Feed
SasStatistics
Pyrite | Level 9

To load a sas table into Python is easy with the pandas module in Python, i.e. pd.read_sas. For documentation of that, see this link: https://www.marsja.se/how-to-read-sas-files-in-python-with-pandas/ 

Now my problem is the following: 

I have SAS tables that I want to read into Python, this is easily done with pd.read_sas. 

Then I will do some work in Python and would finally like to export the data frame to a Sas file directly, is this possible to do? 

Note: I am aware of that the latest version of VIYA can handle Python code inside a SAS session but this is not relevant since in my organization we will not have the latest VIYA version. 

Edit: Writing proc setinit; run;
I get the following: Current version: 9.04.01M5P091317


6 REPLIES 6
Ksharp
Super User

I know SAS can import R dataframe by IML. @Rick_SAS  wrote several blog about it .

Can you change Python into R ?

SasStatistics
Pyrite | Level 9
No, unfortunately I must use Python.
Rick_SAS
SAS Super FREQ

You can use the SASPy package to connect to SAS from Python.  For an introduction, see "How to code in Python with SAS 9.4."

 For more details, including how to transfer data from a Pandas data frame into a SAS data set, see Foreman (2018)

"SAS and Python: The Perfect Partners in Crime"

 

 

Ksharp
Super User
Great ! I just have forgotten SASPY package .
SasStatistics
Pyrite | Level 9

Thanks alot @Rick_SAS, I will read out on all of that.

At a first sight, I must have SAS 9.4 whereas my version is: Current version: 9.04.01M5P091317 . So this will not work 

Do you spontaneously know wether it is possible to (without connecting to SAS or anything) just export a pandas dataframe to a SAS table analogously as I easily could export a dataframe to a CSV or Excel file?

Reeza
Super User
You're interpreting that version incorrectly, you have 9.4M5 which is one of the later versions.

You can find your version of SAS with the following:

proc product_status;run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 5802 views
  • 2 likes
  • 4 in conversation