DATA Step, Macro, Functions and more

SAS + Python/R Integration

Super Contributor
Posts: 339

SAS + Python/R Integration

I would like to consult expertise of the community regarding my plan if it would be feasible.


(1) Load file to SAS

(2) Call python/R to do some treatments on the SAS dataset

(3) Load SAS dataset to RDBMS


If everything is on a sas script, will SAS be able to capture if there are any failures in the pyhton script called?


NOTE: Reason there's a python/R as there were previously built scripts to cleanse the data. While it can be done in SAS thru prxmatch,etc we don't want too waste much effort replacing a working one in python/R


Greatly appreciate your inputs and thoughts on this.


Thank you!

Posts: 1,283

Re: SAS + Python/R Integration

[ Edited ]

not sure about python integration, but you can run R code in proc IML. 


An introduction is given here:


Rick Wicklin, senior researcher in computational statistics at SAS, walks through the process of calling R procedures from SAS/IML software. To learn more about IML and statistical programming in SAS, visit .
Super User
Posts: 10,280

Re: SAS + Python/R Integration

Where does the data for step (1) come from? Do you read from the RDBMS, or from external data?


My preferred method to communicate with other applications is to use a common file format and store the data there.


So I'd try to

(after the data is in SAS)

- write data to a file format suitable for the external application

- run the external application from SAS (XCMD necessary), and catch the return code (suitable wrapper script for external app necessary)

- if RC = 0, read the output back into SAS and transform for loading into the RDBMS


You don't need additional SAS licensing, and the blueprint works for any application that can be run from the commandline.

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 339

Re: SAS + Python/R Integration

Posted in reply to KurtBremser

Thanks I have the same thing in mind in case they push for this approach. But I'm planning to have all the processing done in python as I don't have to let SAS read back and forth data in the dbms

Super User
Super User
Posts: 9,599

Re: SAS + Python/R Integration

I am not seeing the value - load to SAS, run Python, upload to DBMS?  Why not just use Python to load, check and upload to DBMS, or if you are moving to SAS, put the time in to do the migration.  Surely any time you spend maintaining multiple applications will mitigate migration costs (just thinking about validation of installs, updates, etc.).

Super Contributor
Posts: 339

Re: SAS + Python/R Integration

Agree with you on this one as I was also trying to point out to the team that it's either go for python doing the processing and loading of file to dbms. Because loading back and forth to dbms using SAS will be time consuming

Ask a Question
Discussion stats
  • 5 replies
  • 1 like
  • 4 in conversation