Skip to main content

A sas7bdat file reader for Python

Project description

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.

This module is modified by Yao Xiao.

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)

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

sas7bdatx-2.2.3.3.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

sas7bdatx-2.2.3.3-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file sas7bdatx-2.2.3.3.tar.gz.

File metadata

  • Download URL: sas7bdatx-2.2.3.3.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for sas7bdatx-2.2.3.3.tar.gz
Algorithm Hash digest
SHA256 3e5555976488dbd112e4a1c6e406311a1b575f19a3b01bfff7d93297036923ca
MD5 23fb674af5772b2725be125b0efdf1d9
BLAKE2b-256 d77e279b85d0b6d120e3a286c15122a19d623145fae0bacc54a2564cff518d78

See more details on using hashes here.

File details

Details for the file sas7bdatx-2.2.3.3-py3-none-any.whl.

File metadata

  • Download URL: sas7bdatx-2.2.3.3-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for sas7bdatx-2.2.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a7b67eb85d8a19b4d6d644854ad1c06fc91c69ec05fbfd1a0183045688c8c135
MD5 f728be2ca786512838ab51c7b253c4b4
BLAKE2b-256 9fcca8568cc29a7c1972aaff02f033cddd9950eb81a3dcec6d3265b43a4be9c0

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