Import SAS files to SQL databases
Project description
sas2db
Imports SAS files to SQL databases. Supports both *.sas7bdat
and XPORT (*.xpt
) files.
Installation
The SAS software itself is not required.
Usage
SQLite3
sas2db
supports SQLite3 with no additional dependencies or setup, so we'll start with that. To import from SAS to SQLite3:
-
Run the conversion.
sas2db path/to/src.sas7bdat
-
A
src.db
(matching your input file name) will be created. -
Run SQL! Example:
$ sqlite3 src.db sqlite> .tables mydata sqlite> SELECT COUNT(*) FROM mydata; 200
For more options:
sas2db -h
Other databases
Aside from SQLite3, sas2db
supports other databases like PostgreSQL and MySQL. This support comes from SQLAlchemy under the hood, so see their list of supported "dialects".
To use another database:
- Ensure that the destination database is installed, running, created, and accessible from wherever you will be doing the import.
- Install the corresponding driver.
- On the Dialects page, click your preferred database, then under "DBAPI Support", click one of the options.
- The first DBAPI option is probably fine, though you may have to try multiple.
- Run
sas2db
, passing the database URL to the--db
argument.
Example for PostgreSQL:
# create the database
createdb -U postgres sas_import
# install driver
pip3 install psycopg2
# run the import
sas2db --db postgresql+psycopg2://postgres@localhost:5432/sas_import path/to/src.sas7bdat
Development
-
Install Pipenv.
-
Clone/download the repository.
-
From the project directory, run
pipenv install --dev pipenv shell
-
Run PostgreSQL. Example in Docker:
docker run --rm -it -p 5432:5432 --name pg postgres
-
Create
sas2db
database in PostgreSQL for testing. Example in Docker:docker exec -it pg createdb -U postgres sas2db
-
Run tests:
python -m unittest
To use the script:
python3 sas2db/run.py path/to/src.sas7bdat
data.gov has data sets you can test with.
More Information
Other tools to look at for importing/exporting data to/from SAS:
- sas7bdat Python package
- Useful in case you can't use Pandas for some reason
- Pandas (used in
sas2db
) uses a modified version of the sas7bdat package
- SAS ODBC drivers
- SAS's
PROC EXPORT
- sas2bdat R package
Information about data types:
- Documentation
- SAS to Python type parsing
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sas2db-0.2.1.tar.gz
.
File metadata
- Download URL: sas2db-0.2.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4163e81cab643dc6bea68f38a54ffaf15c93b0c987127f7dcba20f309e7038f0 |
|
MD5 | 023e07a74a31afd82805a2539dc38669 |
|
BLAKE2b-256 | c33ac7cdd5c1c5d4a65320693264bb4cb7ea46a6e7bc500fee81a869502fe077 |
File details
Details for the file sas2db-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: sas2db-0.2.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 818294f908201e3a5b51e173fd98b48598dee7d9baf0dfaaf1c2051978554883 |
|
MD5 | c0fa75b6e1e9627c0b1cff7cb927df68 |
|
BLAKE2b-256 | cfbac0c8b675a8fca1f330823783a32870b6488748a2b537e8c0f5d8ceb5b178 |