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 numbername(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
File details
Details for the file sas7bdat-2.2.3.tar.gz.
File metadata
- Download URL: sas7bdat-2.2.3.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
484c609d962442203c15bc719a638de992a23cd13bc1971a5af6dfb0daf9f797
|
|
| MD5 |
0f0a6f124ce25ba1e035c083ee7e5aee
|
|
| BLAKE2b-256 |
4d7bd41d280b12c776e67c840bace0e5f02acda6adb13cd1fbb04293ece0bc3c
|