Comparing SAS Codes with Python Scripts for Developers

Tughluk Abdurazak
February 17, 2023
5 min read

While SAS is still widely respected and used, Python is increasingly becoming the language of choice owing to its open-source and easy to learn nature, as well as its readily available machine learning and artificial intelligence libraries. Based on my experiences using SAS, R, Python, and SQL languages on various client projects and my work developing a SAS-Python automatic conversion tool, I found it would be extremely useful for data analysts and SAS programmers to have a comprehensive list of resources and guides when working on translating SAS code to Python script.


SAS is a powerful tool in data analysis, statistical model development, and data science in general and has been a leading analytic software since 1980s. Many corporations, research institutions, and government agencies have been using SAS as their main analytic tool for years. The SAS DATA step is arguably the most powerful feature in the SAS language, with the ability to union, join, filter, add, remove, and modify columns, along with plainly express conditional and looping business logic. CMS has been one of the major users of SAS software and continues to heavily rely on SAS for data analytics and model development. That is one of the reasons that I have used DE-SynPUFs as raw input for this analysis.


DE-SynPUF was created by CMS with the goal of providing a realistic set of claims data in the public domain while providing the very highest degree of protection to the Medicare beneficiaries’ protected health information.

The purposes of the DE-SynPUF are to:

  1. Allow data entrepreneurs to develop and create software and applications that may eventually be applied to actual CMS claims data;
  2. Train researchers on the use and complexity of conducting analyses with CMS claims data prior to initiating the process to obtain access to actual CMS data; and,
  3. Support safe data mining innovations that may reveal unanticipated knowledge gains while preserving beneficiary privacy.

The files have been designed so that programs and procedures created on the DE-SynPUF will function on CMS Limited Data Sets. The data structure of the Medicare DE-SynPUF is very similar to the CMS Limited Data Sets, but with a smaller number of variables. The DE-SynPUF also provides a robust set of metadata on the CMS claims data that have not been previously available in the public domain. Although the DE-SynPUF has very limited inferential research value to draw conclusions about Medicare beneficiaries due to the synthetic processes used to create the file, the Medicare DE-SynPUF does increase access to a realistic Medicare claims data file in a timely and less expensive manner to spur the innovation necessary to achieve the goals of better care for beneficiaries and improve the health of the population.

DE-SynPUF contains five types of data:

  1. Beneficiary Summary
  2. Inpatient Claims
  3. Outpatient Claims
  4. Carrier Claims
  5. Prescription Drug Events

DE-SynPUFs and documentation can be downloaded from:

SAS Codes and Python Scripts

Using CMS DE-SynPUF as input datasets, I worked out this long list of Python scripts along with equivalent (if any) SAS codes to demonstrate that most of the routine data manipulation steps, SAS data steps, and frequently used PROCs can be relatively easily translated to Python scripts.

I have included SAS codes along with Python scripts in every block; however, you don't need to use SAS here. I don't want to discourage anyone who doesn't know Python. Python is indeed a very easy to learn language.

To run the scripts here, all you need is:

  1. Install Python to your local environment or open a free account.
  2. Learn the basics of Python from free of charge.
  3. Know what and how to install and import Python libraries.
  4. Know at least one SQL language. I have used a lot of SQL examples here because it is being widely used.
  5. Most importantly: Willingness and dedication to learn Python.

Get Started

Download the complete Python code here: Medicare Claims Data Analysis Script

View the list of script examples here (PDF): Medicare Claims Synthetic Public Use Files (SynPUFs) Analysis

Sign up for our newsletter to join our impact-driven mission.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.