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.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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";

 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 14158 views
  • 5 likes
  • 3 in conversation