BookmarkSubscribeRSS Feed
sasprofile
Quartz | Level 8

Hello Friends -

 

Is there any way to execute python code from SAS Environment (Base SAS and SAS EG ?

 

What are all the steps we need to follow or enable any settings or any config changes in SAS inorder to run the python code ?

 

We are using SAS 9.4 M7 on Redhat linux ?

 

Thank you

8 REPLIES 8
Reeza
Super User
Define execute?
Is it an entirely separate process or are you expecting Python to use SAS data sets and such? If it's the latter look into SASpy
If it's the former, look into CALL SYSTEM where you can execute system tasks via SAS. You basically find the command line equivalent (Unix) to execute your Python Script and then ask SAS to execute that command as needed.

sasprofile
Quartz | Level 8
Am looking into to execute Python code within SAS Environment ?
Reeza
Super User
Can you please provide more details.
sasprofile
Quartz | Level 8
Sorry I didnt get you, what details you need ?
Reeza
Super User
Well Python code can be anything from a Flask app to base python to panda's code.

So details would be like what type of python code and libraries you want to use, and what type of code you plan to run. If it's a process to take a CSV file and do something that Python can do but SAS can't then that's probably easy enough. If you want to run a flask app, I'm seeing possible issues. If you're planning to interface with SAS data somehow I'm also seeing issues.
ChrisHemedinger
Community Manager

SAS recently introduced PROC PYTHON -- but it's only in SAS Viya, not in SAS 9.4.

 

You can include Python code within custom functions using PROC FCMP, and that works in SAS 9.4 Maint 7.

 

Or you can run Python scripts by kicking off an external process via SYSTASK or another mechanism to call out to the shell, if that's something you're allowed to do.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
sasprofile
Quartz | Level 8
Thank you Chris
Do I need to enable any settings for this python code to run from SAS Enterprise Guide ?
ChrisHemedinger
Community Manager

A Python runtime (of course) and some environment variables are needed to set it up. See the documentation for the FCMP Python object  and these config instructions.

 

Set these at SAS startup (usually a SAS admin task) or you might be able to use the OPTIONS statement in code right from EG.

 

Examples of setting these (your paths may be different):

options set=MAS_M2PATH="/install/SASServer/SASHome/SASFoundation/9.4/misc/tkmas/mas2py.py"
options set=MAS_PYPATH="/usr/bin/python";

 

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 8 replies
  • 9082 views
  • 5 likes
  • 3 in conversation