SAS to CSV - The Easy Way

Since I don't do much of my work in SAS, but some of the data I receive is in SAS format, I've created a SAS script that can be run from the terminal to convert a .sas7bdat file into an ordinary .csv file (optionally compressed to .csv.gz). There is also a Python script to run batch conversions of many SAS data files in parallel. This requires both Python and SAS to be installed.

The SAS and Python scripts can be found here.

Single file conversion

Make sure SAS is on the path and from the root directory run:

sas sas_to_csv.sas ^
    -set in "<absolute_path>/<filename>.sas7bdat" ^
    -set out "<absolute_path>/<filename>.csv"

Batch conversion

  1. Make sure SAS is on the path
  2. Put the files you want to convert in the data-sas folder
  3. Run the Python script from the root directory:

    python convert_all_files.py
    
  4. Find the exported CSV files in the data-csv folder

More from Peter Alping
All posts