Skip to main content

sas7bdat.py

This module will read sas7bdat files using pure Python (2.6+, 3+). No SAS software required! The module started out as a port of the R script of the same name found here: https://github.com/BioStatMatt/sas7bdat but has since been completely rewritten.

Also included with this library is a simple command line script, sas7bdat_to_csv, which converts sas7bdat files to csv files. It will also print out header information and meta data using the --header option and it will batch convert files as well. Use the --help option for more information.

As is, I've successfully tested the script almost three hundred sample files I found on the internet. For the most part, it works well. We can now read compressed files!

I'm sure there are more issues that I haven't come across yet. Please let me know if you come across a data file that isn't supported and I'll see if I can add support for the file.

Usage

To install, run:

pip install sas7bdat

To create a sas7bdat object, simply pass the constructor a file path. The object is iterable so you can read the contents like this:

#!python
from sas7bdat import SAS7BDAT
with SAS7BDAT('foo.sas7bdat', skip_header=True) as reader:
    for row in reader:
        print row

Each row will be a list of values of type string, float, datetime.date, datetime.datetime, or datetime.time. Without skip_header, the first row returned will be the SAS variable names.

If you'd like to get a pandas DataFrame, use the to_data_frame method:

#!python
df = reader.to_data_frame()

Variable attributes are available from reader.columns. The order of these columns will be the same as the corresponding values in each row. Each Column has the following attributes:

  • col_id (int) - the column number
  • name (bytes)
  • label (bytes)
  • format (str)
  • type (str)
  • length (int)

Download files

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

Source Distribution

sas7bdat-2.3.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

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

sas7bdat-2.3.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file sas7bdat-2.3.0.tar.gz.

File metadata

  • Download URL: sas7bdat-2.3.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.1

File hashes

Hashes for sas7bdat-2.3.0.tar.gz
Algorithm Hash digest
SHA256 ed8bfe652c7e8bb8e8db788da5680fdbe1dada2361ee00fb7eeda032e7388f3d
MD5 4331aec383fce9e7a51661e199260544
BLAKE2b-256 d53c37d38dbbdce403007d26c6e9ca9582d7c847f58f9ba49a27195cb4067c5d

See more details on using hashes here.

File details

Details for the file sas7bdat-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: sas7bdat-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.1

File hashes

Hashes for sas7bdat-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3146912a0a6a10769b48c1a13ae54d696f938f8c1a65c551a70dd8f2c704f10
MD5 74f1fceced3faaa2236079bc1ea1421e
BLAKE2b-256 e0833d5f251650ea1bcb2c765a6de73f3b61cc4d9db4fd536d26cc436db6428a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.3.0 This release

2 files

2.2.3

1 file

2.2.2

1 file

2.2.1

1 file

2.2.0

1 file

2.1.2

1 file

2.1.1

1 file

2.0.7

1 file

2.0.6

1 file

2.0.5

1 file

2.0.4

1 file

2.0.3

1 file

2.0.2

1 file

2.0.1

1 file

2.0.0

1 file

1.0.5

1 file

1.0.4

1 file

1.0.3

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

0.2.5

1 file

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page