RubyPDF Blog machine learning Python For SAS Users

Python For SAS Users

I am a coder, and focus on machine learning now. for some reason, I learned SAS 2 years ago, for a coder,  SAS language is very strange, but I had to learn it. when I am familiar with it, I have to learn Python now.

So I collect some useful resources here,

Comparison with SAS

It is a very useful article from pandas docs,

For potential users coming from SAS this page is meant to demonstrate how different SAS operations would be performed in pandas.

Python For SAS Users

An Introduction to Python for SAS Users

The goal for this content is to permit business users familiar with Base SAS programming to learn Python. The examples provided map SAS programming constructs and coding patterns into their Python equivalents. The primary focus is on pandas and data management issues related to analysis of data.

If you are already familiar with Python you can skip the first three chapters. If you are not familiar with it, make sure to learn how to update python first.

Python for SAS Users: The pandas Data Analysis Library

This post is a chapter from Randy Betancourt’s Python for SAS Users quick start guide. Randy wrote this guide to familiarize SAS users with Python and Python’s various scientific computing tools.

SAS vs. Python – How Do They Compare?


When you see an interesting data set, report, or figure, do you wonder what it would take to replicate those outputs in SAS®? This paper will do just that, by using SAS® to recreate a complex graph that was originally generated by Python.

A key concept for understanding this comparison is that the starting point is the Python code. The paper will associate snippets of Python with the corresponding SAS® statements, attempting a reasonable apples-to-apples comparison. In other words, the resulting SAS® code will not necessarily represent how it would have been written if we had started with SAS® rather than Python. The objective of the paper is to show SAS® programmers how SAS® code lines up with the widely used Python language.

We will start with a brief summary of how SAS® and Python compare across several environmental dimensions. The code comparison will be broken down into the following task areas:

  •  Data manipulation
  •  Data aggregation
  •  Logic
  •  Graphing

The comparison will be summarized by the following measures:

  • Lines of code
  • Run time
  • Readability

The appendices contain the complete programs and the output graphs.


Data manipulation in Python for SAS users, with the %%sasx magic command.

SASX (Simple dAta SyntaX) has the best of both worlds: – Classic python syntax with access to python, numpy, pandas (like Python) – A few extra keywords to allow easy row-by-row operations (like SAS)

Install the latest release with:pip install sasx

Why SAS Programmers Should Learn Python Too

      Day to day work can often require simple, yet repetitive tasks. All companies have tedious processes that may involve moving and renaming files, making redundant edits to code, and more. Often, one might also want to find or summarize information scattered amongst many different files as well. While SAS programmers are very familiar with the power of SAS, the power of some lesser known but readily available tools may go unnoticed.

The programming language Python has many capabilities that can easily automate and facilitate these tasks. Additionally, many companies have adopted Linux and UNIX as their OS of choice. With a small amount of background, and an understanding of Linux/UNIX command line syntax, powerful tools can be developed to eliminate these tedious activities. Better yet, these tools can be written to “talk back” to the user, making them more user friendly for those averse to venturing from their SAS editor. This paper will explore the benefits of how Python can be adopted into a SAS programming world.


The SASPy package enables you to connect to and run your analysis from SAS 9.4 using the object-oriented methods and objects from the Python language as well as the Python magic methods. SASPy translates the objects and methods added into the SAS code before executing the code. To use SASPy, you must have SAS 9.4 and Python 3.x or later.

How to code in Python with SAS 9.4

The SAS® platform is now open to be accessed from open-source clients such as Python, Lua, Java, the R language, and REST APIs to leverage the capabilities of SAS® Viya® products and solutions. You can analyze your data in a cloud-enabled environment that handles large amounts of data in a variety of different formats. To find out more about SAS Viya, see the “SAS Viya: What’s in it for me? The user.” article.

This blog post focuses on the openness of SAS® 9.4 and discusses features such as the SASPy package and the SAS kernel for Jupyter Notebook and more as clients to SAS. Note: This blog post is relevant for all maintenance releases of SAS 9.4.


Read SAS files stored as either XPORT or SAS7BDAT format files.

SparkSQL SAS (sas7bdat) Input Library

A library for parsing SAS data (sas7bdat) with Spark SQL. This also includes a SasInputFormat designed for Hadoop mapreduce. This format is splittable when input is uncompressed thus can achieve high parallelism for a large SAS file.

This library is inspired by spark-csv and currently uses parso for parsing as it is the only public available parser that handles both forms of SAS compression (CHAR and BINARY).

and here is a tutorial about How two read SAS data with PySpark.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.