Skip to main content

Lightweight local SAS language interpreter

Project description

SASLite

SASLite is a lightweight local interpreter for a practical subset of the SAS language, implemented in Python on top of pandas. It is intended for local data checks, small automation workflows, SAS-like examples, and migration/testing work where a full SAS runtime is not available.

SASLite is an independent project. It is not affiliated with, endorsed by, or supported by SAS Institute Inc.

Status

This project is currently alpha software. It supports a useful subset of SAS syntax, but it is not a complete SAS replacement. Validate results carefully before using them for regulated, clinical, financial, or other high-stakes work.

Installation

pip install saslite

Optional extras:

pip install "saslite[excel]"
pip install "saslite[gui]"

For local development from a checkout:

pip install -e ".[excel,gui]"

Command Line

Run a SAS program:

saslite path/to/program.sas

Run one statement:

saslite -e "data demo; x = 1; output; run;"

Start the interactive prompt:

saslite --interactive

Use a persistent working directory for local datasets:

saslite --workdir ./work path/to/program.sas

GUI

Install the GUI extra:

pip install "saslite[gui]"

Start the browser-based GUI:

saslite-gui

This starts a local Flask server at http://127.0.0.1:5000 and opens it in the default browser. To keep it from opening a browser tab automatically:

saslite-gui --no-browser

Start the desktop wrapper, powered by pywebview:

saslite-desktop

On Windows, the desktop wrapper may require Microsoft Edge WebView2 Runtime. The browser-based saslite-gui command is the simpler fallback.

Python API

from saslite import SasInterpreter

sas = SasInterpreter()

result = sas.execute(
    """
    data work.employees;
        input name $ age salary;
        datalines;
    Alice 30 50000
    Bob 25 40000
    ;
    run;

    proc print data=work.employees;
    run;
    """
)

print(result.success)
df = sas.get_dataset("WORK", "EMPLOYEES")
print(df)

Create a SASLite dataset from pandas:

import pandas as pd
from saslite import SasInterpreter

sas = SasInterpreter()
source = pd.DataFrame({"id": [1, 2, 3], "value": [10, 20, 30]})
sas.create_dataset("source", source)

sas.execute(
    """
    data work.result;
        set work.source;
        doubled = value * 2;
    run;
    """
)

result = sas.get_dataset("WORK", "RESULT")

Supported Features

SASLite includes support for:

  • DATA step basics: DATA, SET, INPUT, DATALINES, INFILE, OUTPUT, KEEP, DROP, RENAME, WHERE, IF, DO, BY, FIRST. and LAST.
  • PROC SQL basics: SELECT, CREATE TABLE, joins, grouping, ordering, calculated columns, CASE, LIKE, BETWEEN, IN, IS NULL, and common aggregate functions.
  • PROC steps including PRINT, SORT, CONTENTS, MEANS, SUMMARY, FREQ, IMPORT, EXPORT, APPEND, and DATASETS.
  • LIBNAME references for local work areas.
  • A lightweight macro expander for common macro-variable workflows.
  • Common SAS-style character, numeric, date/time, missing-value, and utility functions.
  • CSV import/export through the Python API and PROC IMPORT/EXPORT.

See DOCS.md and the examples/ directory in the source repository for more complete usage notes.

Examples

data work.sales;
    input region $ product $ amount;
    datalines;
East Widget 100
West Gadget 200
East Widget 150
;
run;

proc sql;
    create table work.summary as
    select region, sum(amount) as total_sales
    from work.sales
    group by region
    order by total_sales desc;
quit;

Run it with:

saslite examples/basic_sql.sas

Known Limits

SASLite intentionally implements a subset of SAS. Some advanced or environment specific SAS features are not supported, including the full macro language, remote libraries, SAS server integration, complete format/informat coverage, ODS, graphics, and every PROC available in commercial SAS.

When SASLite cannot parse or execute a program exactly, simplify the program to the supported subset or use the Python API to prepare input datasets directly.

Development

Install development dependencies:

pip install -e ".[excel,gui]"
pip install pytest build twine

Run tests:

python -m pytest -q

Build distribution artifacts:

python -m build

Check package metadata:

python -m twine check dist/*

Publishing

Test the package on TestPyPI before publishing to PyPI:

python -m build
python -m twine upload --repository testpypi dist/*

After verifying installation from TestPyPI, publish the same version to PyPI:

python -m twine upload dist/*

License

SASLite is distributed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

saslite-0.1.1.tar.gz (122.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

saslite-0.1.1-py3-none-any.whl (121.7 kB view details)

Uploaded Python 3

File details

Details for the file saslite-0.1.1.tar.gz.

File metadata

  • Download URL: saslite-0.1.1.tar.gz
  • Upload date:
  • Size: 122.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for saslite-0.1.1.tar.gz
Algorithm Hash digest
SHA256 08e1b3f720fd16e591c916d9706eeee4be6f8bf8c6c748cda55877ecfda72e2a
MD5 f627de6bd2a8dd2f6e3be66435508478
BLAKE2b-256 6a75adf0b814acfe83880a7b801379d0b7d537b4d96b902a7aad69918ae6ff6f

See more details on using hashes here.

File details

Details for the file saslite-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: saslite-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 121.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for saslite-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8405a30ab583462e10ff857e1e632e06444be37e16660da4afa64661e8e7f2b8
MD5 4e192511bf5252c77342571f0f62ac7c
BLAKE2b-256 12764658f66f6b2ba1e5a8efb22a6b9991964c92fbbd010d13c78e3a1fa3a46e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page