SAS7BDAT (.sas7bdat)

Background & Context

    • MIME type: application/x-sas-data
    • SAS database transport format.
    • Legacy data exchange format.
    • Stores numerical datasets in a portable format.
    • Binary format.
    • Developed in the late 1980s by SAS Institute.

Import

  • Import["file.sas7bdat"] imports a SAS7BDAT file, returning all datasets arranged as a table.
  • SAS7BDAT data is represented in the Wolfram Language by real or integer numbers, strings, Boolean values True and False, and DateObject specifications.
  • Import["file.sas7bdat",elem] imports the specified element from a SAS7BDAT file.
  • Import["file.sas7bdat",{elem,suba,subb,}] imports a subelement.
  • The import format can be specified with Import["file","SAS7BDAT"] or Import["file",{"SAS7BDAT",elem,}].
  • Export["file.sas7bdat",expr] creates a SAS7BDAT file from expr.
  • Supported expressions expr include:
  • {v1,v2,}a single column of data
    {{v11,v12,},{v21,v22,},}lists of rows of data
    arrayan array such as SparseArray, QuantityArray, etc.
    tseriesa TimeSeries, EventSeries or a TemporalData object
    Dataset[]a dataset
    <|"name1"expr1,|>an association of named columns
  • Import and Export support the following data types:
  • "Date"date and time specifications
    "Integer8"8-bit integers
    "Integer16"16-bit integers
    "Integer32"32-bit integers
    "Real32"IEEE singleprecision numbers
    "Real64"IEEE doubleprecision numbers
    "String"string of characters
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • Data representation elements:
  • "Data"two-dimensional array
    "Dataset"table data as a Dataset
    "LabeledData"association of labels and data
  • Import by default uses the "Data" element.
  • Data descriptor elements:
  • "ColumnDescriptions"description and types of columns
    "Labels"names of columns
    "MissingPositions"positions of elements considered to be missing per column
    "MissingValues"values to be considered missing per column
  • Metadata elements:
  • "ByteOrdering"endianness of the data
    "CharacterEncoding"character encoding of the file
    "Comments"comments on the file
    "Compression"type of compression used in the file
    "CreationDate"creation date of the document, given as a DateObject
    "Dimensions"dimensions of the data
    "MetaInformation"metadata given as strings and date objects
    "ModificationDate"modification date of the document, given as a DateObject
    "TableName"name of the entire table
    "Version"version of the SAS specification for the file

Options

  • Import options:
  • "ColumnDefaultValues"Automaticassociation of column names and default values
    "TypeDefaultValues"Automaticassociation of types and default values
  • Export options:
  • "ColumnDescriptions"Automaticlist of descriptions for each column
    "MetaInformation"Automaticassociation of metadata tags and values
  • Possible settings for "ColumnDescriptions" include:
  • {"label1", "label2", }list of strings giving column names
    {assoc,}list of associations giving column metadata
    <|colassoc|>association of index or column name and column metadata
  • Possible keys for assoc include:
  • "Name"string giving the column's name
    "Description"string giving the column's description
    "Type"string giving the column's type
  • Possible keys for "MetaInformation" include:
  • "Comments"string giving general comments on the file
    "CreationDate"date object giving the creation date of the file
    "ModificationDate"date object giving the modification date of the file
    "TableName"string giving the name of the entire table
    "Version"integer giving the version of the file

Examples

open allclose all

Basic Examples  (3)

Import a SAS7BDAT file:

Summary of a SAS7BDAT file:

Export an array of expressions to a SAS7BDAT file:

Import the resulting file as a dataset:

Scope  (6)

Export a Dataset:

Column names are automatically inferred:

Export an array of data:

Export an association of named columns:

Column names are automatically inferred:

Export a TimeSeries:

Times are stored in the first column, values in the second:

Export tagged missing data:

Ragged arrays are automatically padded on the right and converted to full arrays:

Import Elements  (15)

Data Representation  (3)

"Data"  (1)

Import a SAS7BDAT file as a 2D list of values:

This is also the default element:

"Dataset"  (1)

Import a SAS7BDAT file as a Dataset:

"LabeledData"  (1)

Import a SAS7BDAT file as an association of labels and data:

Data Descriptors  (3)

"ColumnDescriptions"  (1)

Import associations giving the name, description and type for each column in a SAS7BDAT file:

"Labels"  (1)

Import the names of each column in a SAS7BDAT file:

"MissingPositions"  (1)

Import associations giving the positions of missing values by column:

Metadata  (9)

"ByteOrdering"  (1)

Import the byte ordering stored in the metadata of a SAS7BDAT file:

"CharacterEncoding"  (1)

Import the character encoding stored in the metadata of a SAS7BDAT file:

"Comments"  (1)

Import comments stored in the metadata of a SAS7BDAT file:

"CreationDate"  (1)

Import the creation date:

"Dimensions"  (1)

Import the data dimensions:

"MetaInformation"  (1)

Import an association of all the metadata stored in a SAS7BDAT file:

"ModificationDate"  (1)

Import the modification date:

"TableName"  (1)

Import the table name stored in the metadata of a SAS7BDAT file:

"Version"  (1)

Import the version of a SAS7BDAT file:

Import Options  (2)

"ColumnDefaultValues"  (1)

Missing numerical values are replaced with zero by default:

Use "ColumnDefaultValues" to specify a different default value for specific columns:

"TypeDefaultValues"  (1)

Missing numerical values are replaced with zero by default:

Use "TypeDefaultValues" to specify a different default value for specific types:

Export Options  (2)

"ColumnDescriptions"  (1)

Export different data types:

Columns will automatically infer types based on the data given:

Use "ColumnDescriptions" to specify column types and descriptions:

Import the resulting column descriptions:

"MetaInformation"  (1)

Retrieve the metainformation from a SAS7BDAT file:

Export a new file with the same metainformation: