Skip to main content

Convert SAS datasets (.sas7bdat files) to Polars DataFrames.

Project description

sas_to_polars

A light Python package for converting and processing SAS datasets (.sas7bdat files) into a Polars DataFrame. Designed for high-performance data transformation by leveraging parallel computing.


Table of Contents


Overview

This package provides a fast and convenient way to read SAS datasets into Polars DataFrames. Converting SAS datasets in Python often requires specific libraries. For large datasets, the conversion process can be a bottleneck. This package addresses this by leveraging concurrent programming to speed up the conversion.

sas_to_polars allows users to quickly transform their SAS data into the efficient Polars DataFrame structure for further analysis and manipulation in Python.


Installation

This package requires Python 3.8 or higher.

The following Python libraries are necessary and will be installed as dependencies:

  • pyreadstat: For reading SAS datasets.
  • polars: For high-performance data manipulation.
  • pyarrow: For efficient data conversion (required by Polars).

You can install sas_to_polars using pip:

pip install sas-to-polars  # Replace with your actual package name on PyPI

After running this command, pip will resolve and install the required dependencies (pyreadstat and polars) along with your sas_to_polars package.

To verify the installation, you can run: python -c "import sas_to_polars

If no output is returned, the installation was successful.


Usage

The primary function in this package is sas_to_polars. Here's how to use it.

from sas_to_polars import sas_to_polars

df = sas_to_polars(filepath="path/to/dataset/data.sas7bdat")
print(df.head())

The sas_to_polars function accepts the following optional parameters:

  • chunksize: int = 10_000: The number of rows to read in each chunk during parallel processing.
  • processes: int = mp.cpu_count() // 4: The number of parallel processes to use for conversion. Defaults to a quarter of the available CPU cores.
  • use_lazy: bool = True: Whether to use Polars lazy loading for potentially more efficient out-of-memory operations.
  • unordered: bool = False: Whether to maintain the original order of columns from the SAS dataset.

For more detailed information about the sas_to_polars function and its parameters, you can use Python's built-in help function:

help(sas_to_polars)

Example Dataset Output

Shape: (3, 3)
┌─────┬─────────┬──────┐
│ id  ┆ name    ┆ age  │
│ --- ┆ ---     ┆ ---  │
│ f64 ┆ str     ┆ f64  │
╞═════╪═════════╪══════╡
│ 1.0 ┆ Alice   ┆ 30.0 │
│ 2.0 ┆ Bob     ┆ 35.0 │
│ 3.0 ┆ Charlie ┆ 40.0 │
└─────┴─────────┴──────┘

License

This project is licensed under the MIT License - see the LICENSE file 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

sas_to_polars-1.0.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

sas_to_polars-1.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file sas_to_polars-1.0.0.tar.gz.

File metadata

  • Download URL: sas_to_polars-1.0.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for sas_to_polars-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7cfb91b09cf9cbcbdec68f80b5f7661b47eaacff6f19440cb0d1d68b0756ab55
MD5 a29d95729580affff747ded4f78cb355
BLAKE2b-256 249421459f8f54c50a49b9e40cfed0ae11e9afaed076f5c1b57831faaf8cd61a

See more details on using hashes here.

File details

Details for the file sas_to_polars-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sas_to_polars-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for sas_to_polars-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1bd4dd3565cf4b87d0719350166d210b475514ca34622afcdd13689b9a654add
MD5 3c4ad0e5cdc5e2a376a2899b76678e24
BLAKE2b-256 2db6d18b9090bec56c51196382beb3decca213e497da29264e34771b7af875ba

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