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

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.0.tar.gz (106.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.0-py3-none-any.whl (105.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: saslite-0.1.0.tar.gz
  • Upload date:
  • Size: 106.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.0.tar.gz
Algorithm Hash digest
SHA256 9f880888854fcf88b32f77879a01fe62355c28f0ddb596a632b4edbe0a75cb2e
MD5 26be9925f88578acf8741c96ad203f26
BLAKE2b-256 5a21e50f1e2bcbb17a862d40f673bd5afd779fe788c5bdf35e9a3c2e7d85f4d3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: saslite-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 105.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f54d75e4d67fef98906d55aed5ed6cbae9c67c346be6910356f327e17e03591
MD5 b96b1807777de191e59009eefc8257f1
BLAKE2b-256 dfae4d592461ad7a67e2a5264c65af330b77659fdb6316776a0ce608213aad53

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