Back to Tech Corner
SAS Programming

SAS PROC Python: A Basic Introduction

SAS PROC PYTHON is a SAS procedure that enables Python code to run directly inside a SAS program, allowing organizations to combine the reliability of SAS analytics with the flexibility of Python. It provides a streamlined method for integrating open-source Python libraries such as pandas, NumPy, matplotlib, and scikit-learn into SAS-driven workflows. This approach helps data engineers, statisticians, and developers work within a single environment instead of maintaining separate SAS and Python processing pipelines.

Availability

PROC PYTHON is primarily available in modern SAS Viya environments and is designed to support open-source integration strategies commonly used in enterprise analytics and data science platforms. It is not a standard feature of traditional Base SAS 9.4 deployments (PROC PYTHON will be available in SAS 9.4 M10, slated to release 2nd quarter 2027). In SAS Viya, PROC PYTHON can interact with CAS-enabled data, execute Python logic, and support hybrid analytics solutions combining SAS procedures with Python-based machine learning or automation tasks.

Operational Efficiency

One of the major advantages of PROC PYTHON is operational efficiency. Organizations that already rely on SAS for governance, security, reporting, and enterprise analytics can incorporate Python capabilities without redesigning their architecture. This improves interoperability between SAS developers and Python developers while preserving centralized administration and auditability.

Example 1 – Using pandas to Analyze SAS Data

proc python;
submit;
import pandas as pd
df = SAS.sd2df("sashelp.class")
print(df.head())
endsubmit;
run;

In this example, a SAS dataset is converted into a pandas DataFrame for Python-based analysis.

Example 2 – Using Python Machine Learning Within SAS

proc python;
submit;
from sklearn.linear_model import LinearRegression
import pandas as pd
df = SAS.sd2df("sashelp.cars")
X = df[['Horsepower']]
y = df['MPG_City']
model = LinearRegression()
model.fit(X, y)
print(model.coef_)
endsubmit;
run;

This example demonstrates how Python machine learning libraries can operate directly within a SAS-managed workflow.

Where PROC PYTHON Fits

PROC PYTHON is particularly valuable for organizations adopting modern analytics practices, AI initiatives, API integrations, and open-source collaboration while continuing to leverage enterprise-grade SAS infrastructure.