Skip to main content

Convert sas7bdat and xport files into other formats

Project description

sas7bdat-converter: Convert sas7bdat files into other formats

Tests Status pre-commit.ci status Coverage PyPI version PyPI - Python Version

Converts proprietary sas7bdat and/or xport files from SAS into formats such as csv, json, and Excel useable by other programs. Currently supported conversiaions are csv, Excel (xlsx format), json, Pandas DataFrame, and XML.

Conversions can be done on either a single file, an entire directory, or a batch of specified files.

Install

pip install sas7bdat-converter

If you would like to be able to convert to Excel files you will need to install with the extra Excel dependency.

pip install sas7bdat-converter[excel]

Usage

In all cases either sas7bdat or xport files can be converted. Examples below all use the .sas7bdat extension, xport files with a .xpt extension will also work.

  • batch_to_csv(file_dicts) - Convert multiple sas7bdat files into csv files at once.

    • file_dicts = A list containing a dictionary for each file to convert. The dictionary is required to contain 'sas7bdat_file' containing the path and name for the sas7bdat file, and 'export_file' containing the path and name for the csv files. The csv file extension should be .csv. File paths can be sent as either strings or Path objects.
    • continue_on_error = If set to true processing of files in a batch will continue if there is a file conversion error instead of raising an exception. Default = False

    Example

    import sas7bdat_converter
    
    file_dicts = [
      {
        'sas7bdat_file': '/path/to/sas7bdat/files/example_1.sas7bdat',
        'export_file': '/path/to/new/files/example_1.csv',
      },
      {
        'sas7bdat_file': '/path/to/sas7bdat/files/example_2.sas7bdat',
        'export_file': '/path/to/new/files/example_2.csv',
      },
    ]
    sas7bdat_converter.batch_to_csv(file_dicts)
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files\example_1.sas7bdat.

  • batch_to_excel(file_dicts) - Convert multiple sas7bdat files into Excel files at once.

    • file_dicts = A list containing a dictionary for each file to convert. The dictionary is required to contain 'sas7bdat_file' containing the path and name for the sas7bdat file, and 'export_file' containing the path and name for the excel files. The Excel file extension should be .xlsx. File paths can be sent as either strings or Path objects.
    • continue_on_error = If set to true processing of files in a batch will continue if there is a file conversion error instead of raising an exception. Default = False

    Example

    import sas7bdat_converter
    
    file_dicts = [
      {
        'sas7bdat_file': '/path/to/sas7bdat/files/example_1.sas7bdat',
        'export_file': '/path/to/new/files/example_1.xlsx',
      },
      {
        'sas7bdat_file': '/path/to/sas7bdat/files/example_2.sas7bdat',
        'export_file': '/path/to/new/files/example_2.xlsx',
      },
    ]
    sas7bdat_converter.batch_to_excel(file_dicts)
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files\example_1.sas7bdat.

  • batch_to_json(file_dicts) - Convert multiple sas7bdat files into json files at once.

    • file_dicts = A list containing a dictionary for each file to convert. The dictionary is required to contain 'sas7bdat_file' containing the path and name for the sas7bdat file, and 'export_file' containing the path and name for the json files. The json file extension should be .json. File paths can be sent as either strings or Path objects.
    • continue_on_error = If set to true processing of files in a batch will continue if there is a file conversion error instead of raising an exception. Default = False

    Example

    import sas7bdat_converter
    
    file_dicts = [
      {
        'sas7bdat_file': '/path/to/sas7bdat/files/example_1.sas7bdat',
        'export_file': '/path/to/new/files/example_1.json',
      },
      {
        'sas7bdat_file': '/path/to/sas7bdat/files/example_2.sas7bdat',
        'export_file': '/path/to/new/files/example_2.json',
      },
    ]
    sas7bdat_converter.batch_to_json(file_dicts)
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files\example_1.sas7bdat.

  • batch_to_xml(file_dicts) - Convert multiple sas7bdat files into XML files at once.

    • file_dicts = A list containing a dictionary for each file to convert. The dictionary is required to contain 'sas7bdat_file' containing the path and name for the sas7bdat file, and 'export_file' containing the path and name for the xml files. The XML file extension should be .xml. File paths can be sent as either strings or Path objects.
    • continue_on_error = If set to true processing of files in a batch will continue if there is a file conversion error instead of raising an exception. Default = False

    Example

    import sas7bdat_converter
    
    file_dicts = [
      {
        'sas7bdat_file': '/path/to/sas7bdat/files/example_1.sas7bdat',
        'export_file': '/path/to/new/files/example_1.xml',
      },
      {
        'sas7bdat_file': '/path/to/sas7bdat/files/example_2.sas7bdat',
        'export_file': '/path/to/new/files/example_2.xml',
      },
    ]
    sas7bdat_converter.batch_to_xml(file_dicts)
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files\example_1.sas7bdat.

  • dir_to_csv(dir_path, export_path=None) - Convert all sas7bdat files in a directory into csv files at once. File paths can be sent as either strings or Path objects.

    • dir_path = The dictionary that contains the sas7bdat file to convert.
    • export_path = Optional path for the converted files. If no path is supplied the new files will be put into the dir_path directory with the sas7bdat files. File paths can be sent as either strings or Path objects. Default = None
    • continue_on_error = If set to true processing of files in a batch will continue if there is a file conversion error instead of raising an exception. Default = False

    Example

    import sas7bdat_converter
    
    # Option 1: put the converted files in the same directory as the sas7bdat files
    sas7bdat_converter.dir_to_csv('/path/to/sas7bdat/files')
    
    # Option 2: put the converted fiels in a diffferent directory
    sas7bdat_converter.dir_to_csv('/path/to/sas7bdat/files', 'path/for/new/files')
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files.

  • dir_to_excel(dir_path, export_path=None) - Convert all sas7bdat files in a directory into Excel files at once. File paths can be sent as either strings or Path objects.

    • dir_path = The dictionary that contains the sas7bdat file to convert.
    • export_path = Optional path for the converted files. If no path is supplied the new files will be put into the dir_path directory with the sas7bdat files Default = None
    • continue_on_error = If set to true processing of files in a batch will continue if there is a file conversion error instead of raising an exception. Default = False

    Example

    import sas7bdat_converter
    
    # Option 1: put the converted files in the same directory as the sas7bdat files
    sas7bdat_converter.dir_to_excel('/path/to/sas7bdat/files')
    
    # Option 2: put the converted fiels in a diffferent directory
    sas7bdat_converter.dir_to_excel('/path/to/sas7bdat/files', 'path/for/new/files')
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files.

  • dir_to_json(dir_path, export_path=None) - Convert all sas7bdat files in a directory into json files at once. File paths can be sent as either strings or Path objects.

    • dir_path = The dictionary that contains the sas7bdat file to convert.
    • export_path = Optional path for the converted files. If no path is supplied the new files will be put into the dir_path directory with the sas7bdat files. Default = None
    • continue_on_error = If set to true processing of files in a batch will continue if there is a file conversion error instead of raising an exception. Default = False

    Example

    import sas7bdat_converter
    
    # Option 1: put the converted files in the same directory as the sas7bdat files
    sas7bdat_converter.dir_to_json('/path/to/sas7bdat/files')
    
    # Option 2: put the converted fiels in a diffferent directory
    sas7bdat_converter.dir_to_json('/path/to/sas7bdat/files', 'path/for/new/files')
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files.

  • dir_to_xml(dir_path, export_path=None) - Convert all sas7bdat files in a directory into XML files at once. File paths can be sent as either strings or Path objects.

    • dir_path = The dictionary that contains the sas7bdat file to convert.
    • export_path = Optional path for the converted files. If no path is supplied the new files will be put into the dir_path directory with the sas7bdat files. Default = None
    • continue_on_error = If set to true processing of files in a batch will continue if there is a file conversion error instead of raising an exception. Default = False

    Example

    import sas7bdat_converter
    
    # Option 1: put the converted files in the same directory as the sas7bdat files
    sas7bdat_converter.dir_to_xml('/path/to/sas7bdat/files')
    
    # Option 2: put the converted fiels in a diffferent directory
    sas7bdat_converter.dir_to_xml('/path/to/sas7bdat/files', 'path/for/new/files')
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files.

  • to_csv(sas7bdat_file, export_file) - convert a sas7bdat file into a csv file. File path can be sent as either a string or Path objects.

    • sas7bdat_file = the path and name for sas7bdat file to convert.
    • export_file = the path and name for the csv file. The csv file extension should be .csv.

    Example

    import sas7bdat_converter
    
    sas7bdat_converter.to_csv('/path/to/sas7bdat/file/example.sas7bdat', 'path/to/new/file/example.csv')
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files\example.sas7bdat.

  • to_dataframe(sas7bdat_file) - Convert a sas7bdat file into a Pandas DataFrame. File path can be sent as either a string or Path objects.

    • sas7bdat_file = The path and name for sas7bdat file to convert.

    Example

    import sas7bdat_converter
    
    sas7bdat_converter.to_dataframe('/path/to/sas7bdat/file/example.sas7bdat')
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files\example_1.sas7bdat.

  • to_excel(sas7bdat_file, export_file) - convert a sas7bdat file into a Excel file. File path can be sent as either a string or Path objects.

    • sas7bdat_file = the path and name for sas7bdat file to convert.
    • export_file = the path and name for the Excel file. The Excel file extension should be .xlsx.

    Example

    import sas7bdat_converter
    
    sas7bdat_converter.to_excel('/path/to/sas7bdat/file/example.sas7bdat',
    'path/to/new/file/example.xlsx')
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files\example.sas7bdat.

  • to_json(sas7bdat_file, export_file) - convert a sas7bdat file into a json file. File path can be sent as either a string or Path objects.

    • sas7bdat_file = the path and name for sas7bdat file to convert.
    • export_file = the path and name for the json file. the json file extension should be .json.

    Example

    import sas7bdat_converter
    
    sas7bdat_converter.to_json('/path/to/sas7bdat/file/example.sas7bdat', 'path/to/new/file/example.json')
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files\example.sas7bdat.

  • to_xml(sas7bdat_file, export_file, root_node='root', first_node='item') - convert a sas7bdat file into a XML file. File path can be sent as either a string or Path objects.

    • sas7bdat_file = the path and name for sas7bdat file to convert.
    • export_file = the path and name for the XML file. The XML file extension should be .xlm.
    • root_node = The name to uses for the top level node. If no name is supplied "root" will be used.
    • first_node = The name to use for the first node under root. If no name is supplied "item" will be used.

    Example

    import sas7bdat_converter
    
    sas7bdat_converter.to_xml('/path/to/sas7bdat/file/example.sas7bdat', 'path/to/new/file/example.xml')
    

    Note: Example uses Mac/Linux type file paths. For Windows use paths like c:\path\to\sas7bdat\files\example.sas7bdat.

Contributing

If you are interested in contributing to this project please see our contributing guide

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

sas7bdat_converter-4.0.0.tar.gz (102.9 kB view details)

Uploaded Source

Built Distribution

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

sas7bdat_converter-4.0.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file sas7bdat_converter-4.0.0.tar.gz.

File metadata

  • Download URL: sas7bdat_converter-4.0.0.tar.gz
  • Upload date:
  • Size: 102.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sas7bdat_converter-4.0.0.tar.gz
Algorithm Hash digest
SHA256 11227c2707b6c423427cf00c151c7eb8c0af01e3c87b0790b3e5c656f489e32c
MD5 74c2c357a9711c23b06b8daac6e384a8
BLAKE2b-256 48dad56f419994dd8d477919f7241fffd94ef89141c757890f54c78bd4cc499a

See more details on using hashes here.

File details

Details for the file sas7bdat_converter-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: sas7bdat_converter-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sas7bdat_converter-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c04d25f77bd4156341968d135320aaa4044e62b8b15507fd33950b6e186011ae
MD5 72e2644625c84c725ead0d5caa13164f
BLAKE2b-256 082a63cd7decd4a866776ae0285eb52042df34a2c1371d850bca2db14b789de1

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