SAS to Python: What It Really Takes

Most results for this search are tools that produce Python from SAS source, and several of them do that job well. This page starts one step earlier — with whether the move is right for your codebase at all, what the output costs to verify, and what to do when the answer turns out to be no.

The short answer

There are four routes out of a SAS codebase, not two: hand it to an automated tool, rewrite it by hand, run the SAS programs as they are on something that is not SAS, or leave it alone. Which one is right turns almost entirely on two questions — how much code there is, and whether anyone has to reproduce the output it produced before. Everything below is what each route costs.

When Python is the right answer

Python is the better destination more often than a page like this one usually admits. Four conditions make it clear-cut: the codebase is small enough for one person to read in a week, the team already writes Python day to day, the analysis is being rebuilt anyway, and nothing downstream requires the new numbers to match the old ones exactly. When all four hold, a rewrite is cheaper than any compatibility layer, and what you end up with is code your team can maintain without carrying a second language.

Four routes, and what each one costs

Every option here is the right answer for somebody. None of them is without cost, and the expensive part is never the syntax.

An automated converter

Web tools, vendor services and large language models take .sas source and return Python, usually mapping DATA steps onto pandas and the common procedures onto statsmodels or scikit-learn. For a few hundred lines of straightforward data manipulation that is a genuine shortcut, and it gives you a readable starting point in minutes. The bill arrives later: every line of the output needs a person who knows both languages to read it.

A rewrite by hand

Someone reads the SAS program, works out what it was meant to do, and writes that in Python. It is slower to start and it is the only route that ends with code shaped like Python rather than like SAS wearing a Python coat. Teams that are happy with Python two years later mostly got there this way, usually keeping the old program running alongside until the numbers agreed.

Run the programs as written — 100 procedures

The route the comparison pages skip. Jenner is a clean-room implementation of the SAS 9.4 language written in Rust: it reads SAS7BDAT files directly and executes .sas source as it stands, so there is no generated code to review and no second language for the team to carry. What it does not do is cover the whole SAS language, and the coverage is published procedure by procedure so you can check yours before you depend on it.

Stay where you are

Doing nothing is a real decision and often the correct one. If the code is stable, the environment it runs in is not going away this year, and nobody is asking for a change, the migration you do not do has the best return of anything on this page. Revisit it when a platform move, an audit, or a hiring problem forces the question.

What converted code costs to trust

The failure mode of an automated conversion is not a syntax error; those surface the first time the code runs. It is the silent numerical difference. SAS pads character values with trailing blanks and Python does not, SAS counts dates from 1 January 1960 while pandas counts from 1 January 1970, and a DATA step MERGE does not behave like a pandas merge when the key repeats on both sides. None of that raises anything. It produces a number that is nearly right, which is the worst kind of wrong. So the real price of a conversion is a line-by-line read by someone fluent in both languages, plus a stretch of running old and new side by side on the same input until the outputs agree — and that price scales with how much code there is, not how clever it is.

Frequently Asked Questions

Yes, and the tools are better than they were. Web converters and vendor services will take a .sas file and hand back Python, and a large language model (LLM) will do the same from a chat window. All of them are good at syntax, and none of them can tell you whether the numbers still match. Treat the output as a first draft written by somebody who has never seen your data.

No. It is published by Jenner, which is an independent, clean-room implementation of the SAS 9.4 language written in Rust. It runs .sas programs as they are written, against the SAS7BDAT files you already have. Nothing is emitted in another language, so there is no generated source for anyone to review.

Usually one Python file per SAS program: DATA steps rendered as pandas operations, PROC SQL as either pandas joins or SQL through a database driver, and the statistical procedures mapped onto statsmodels, scipy or scikit-learn where an equivalent exists. Where no equivalent exists — much of the macro facility, ODS output, many formats and informats — the tool leaves a comment or its best guess. That gap is where the review time goes.

There are good ones, and they all share a limit worth knowing before you lean on one. A cheat sheet maps PROC MEANS onto a pandas describe, PROC FREQ onto value_counts or a crosstab, PROC SORT onto sort_values, and a DATA step onto a chain of assignments. That is the syntax layer, and the syntax layer is not the hard part. What no table can map is the semantics underneath — missing-value handling, BY-group processing, trailing blanks in character comparisons, the date origin — and that is where converted code goes quietly wrong.

Yes, and for a short program it is often the shortest path to a first draft. The catch is every converter's catch, made sharper by fluency: an LLM writes code that reads convincingly whether or not it is correct, and it will invent a plausible-looking equivalent for a procedure option it does not know. The fix is not better prompting. It is giving the model a way to execute both versions and compare the output, so the check is mechanical rather than a question of how confident the answer sounded.

Nobody can tell you from the outside, and a page that quotes you a number is guessing. The two variables that matter are how many lines there are and how hard the requirement is that new output match old output. A few thousand lines with no reproduction requirement is a project a small team finishes; a validated codebase whose prior results have to be reproducible is a programme with a testing budget attached, and the coding is the small part of it.

When the output has to reproduce what the old programs produced and somebody outside the team will check that. When the codebase is large enough that nobody alive has read all of it. When the people who understand the analysis are not the people who write Python. Any one of those turns a coding job into a validation job, and validation is what makes these projects overrun.

Running the SAS programs without SAS. An independent implementation of the SAS language executes the .sas source you already have, which means there is no generated code to review and no second language in the room. Jenner is one of these. Altair SLC, formerly WPS, is another and has been at it far longer. This route is worth pricing whenever the reason for leaving is the platform or the licence rather than the language itself.

Yes. SAS7BDAT files are read directly, so nothing has to be exported to CSV first. That matters more than it sounds. A migration that begins by dumping every dataset to text inherits a second set of differences — encodings, numeric precision, date parsing — stacked on top of the ones in the code, and then nobody can tell which layer a discrepancy came from.

Not the whole SAS language, and that is the honest limit to weigh against everything above. Each procedure that is implemented has a published reference page, so whether a specific PROC is supported is something you can check before you depend on it rather than discover afterwards. Programs leaning on uncommon procedure options, ODS layouts, or external database engines are the first places to look. The practical test is to run your own programs and compare the logs, which takes an afternoon and settles the question better than any claim on a page like this one.

Altair SLC, which was WPS, runs SAS-language programs without SAS and has done so for far longer than we have. On a large estate, where somebody else has already hit your edge case and had it fixed, that history is worth real money. Put both in front of your own code and compare the logs. The answer is usually obvious inside a day, and it is not always us.

That is the common ending and a reasonable one. New analyses get written in Python because that is where the team and the libraries already are, while the older validated programs keep running as they stand until there is a reason to touch them. It avoids the worst version of this decision, a big-bang rewrite of code nobody has the budget to re-validate. The two sides only have to agree at the boundary — the data they hand each other — rather than line by line.

Settle it against your own programs

Your code, your data, and the logs side by side. That is the comparison that decides this, and it is the one nobody else can run for you.

Start Free Trial