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.
  • %INCLUDE for composing local SAS programs from multiple files.
  • 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.2.tar.gz (124.6 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.2-py3-none-any.whl (123.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: saslite-0.1.2.tar.gz
  • Upload date:
  • Size: 124.6 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.2.tar.gz
Algorithm Hash digest
SHA256 fafce31c6d00e172ade1164a3467bbd05fa40f467078ca405f0e6a90111596a4
MD5 ff4f4b04a1204f5a5717485e5aaf6807
BLAKE2b-256 9efc15cac8255dde1d94a0fb2fa2de9af977e4a3aa20fdd27e446e8558790c14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: saslite-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 123.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 81db83ab08bed99a7383e1b599259f91cefc4835c2e9c0aeda5e2d1029e72c2c
MD5 ea0db3458b9eb60648fed17f3098f565
BLAKE2b-256 a36736e41c57e6d6529ff88b08a04b45d5814d13eb1c027151d9bcc82f54ae18

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