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 & Export
- 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 dataarray an array such as SparseArray , QuantityArray , etc.tseries a TimeSeries , EventSeries or a TemporalData object<|"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 single‐precision numbers"Real64" IEEE double‐precision numbers"String" string of characters
- See the following reference pages for full general information:
-
CloudImport , CloudExport import from or export to a cloud objectImportString , ExportString import from or export to a stringImportByteArray , ExportByteArray import 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"EventSeries" table data as an EventSeries"LabeledData" association of labels and data"LabeledRawData" association of labels and raw data"Tabular" table data as a Tabular object"TimeSeries" table data as a TimeSeries
- Import by default uses the "Data" element.
- Data descriptor elements:
-
"ColumnDescriptions" description and types of columns"ColumnLabels" names of columns"ColumnTypes" association of column names and types"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" Automatic association of column names and default values"TimeColumn" Automatic column to use for times in "EventSeries" and "TimeSeries" elements"TypeDefaultValues" Automatic association of types and default values
- Export options:
-
"ColumnDescriptions" Automatic list of descriptions for each column"MetaInformation" Automatic association 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 all close allBasic Examples (3)
Import a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat"]Summary of a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "Summary"]Export an array of expressions to a SAS7BDAT file:
file = Export["test.sas7bdat", {{"String1", DateObject[{2000, 1, 1}, "Day"], Missing["NotAvailable"], 8.25}, {"String2", DateObject[{2000, 1, 2}, "Day"], 0.41, 1.44}, {"String3", DateObject[{2000, 1, 3}, "Day"], Missing["NotAvailable"], Missing["Tagged", "A"]}}]Import the resulting file as a dataset:
Import[file, "Tabular"]Scope (9)
Import (3)
Import all available elements:
Import["test.sas7bdat", "Elements"]Import data:
Import["test.sas7bdat", "Data"]Import as a Tabular object:
Import["test.sas7bdat", "Tabular"]Export (6)
Export a Dataset :
dataset = Dataset[{
<|"a" -> 1, "b" -> DateObject[{2000, 1, 1}, "Day"]|>,
<|"a" -> 2, "b" -> DateObject[{2000, 1, 2}, "Day"]|>,
<|"a" -> 3, "b" -> DateObject[{2000, 1, 3}, "Day"]|>}]file = Export["test.sas7bdat", dataset];Column names are automatically inferred:
Import[file, "Dataset"]Export an array of data:
file = Export["test.sas7bdat", {{1, 2, 3}, {4, 5, 6}}]Import[file, "Dataset"]Export an association of named columns:
file = Export["test.sas7bdat", <|"a" -> {1, 2, 3}, "b" -> {4, 5, 6}|>]Column names are automatically inferred:
Import[file, "Dataset"]Export a TimeSeries :
t = {1, 2, 5, 10, 12, 15};
v = {2, 1, 6, 5, 7, 4};ts = TimeSeries[v, {t}]file = Export["test.sas7bdat", ts]Times are stored in the first column, values in the second:
Import[file, "Dataset"]Export tagged missing data:
file = Export["test.sas7bdat", {{1., 2.}, {Missing["Tagged", "A"], 4.}}]Import[file, "Dataset"]Ragged arrays are automatically padded on the right and converted to full arrays:
file = Export["test.sas7bdat", {a, {d, e, f}}]Import[file, "Dataset"]Import Elements (20)
Data Representation (7)
"Data" (1)
Import a SAS7BDAT file as a 2D list of values:
Import["ExampleData/sample.sas7bdat", "Data"]This is also the default element:
Import["ExampleData/sample.sas7bdat"]"Dataset" (1)
Import a SAS7BDAT file as a Dataset :
Import["ExampleData/sample.sas7bdat", "Dataset"]"EventSeries" (1)
Export a Tabular object to a SAS7BDAT file:
file = Export["test.sas7bdat", Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Date" -> Association["ElementType" -> TypeSpecifier["Date"]["Integer32", "Day",
"Gregorian", 0]], "Value" -> Association["ElementType" -> "Real32"]],
"KeyColumns" -> None, "Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {5, {{NumericArray[{13150, 13151, 13152, 13153, 13156},
"Integer32"], {}, None}}, None}, "ElementType" -> "Date"["Integer32", "Day",
"Gregorian", 0]]], TabularColumn[Association["Data" ->
{NumericArray[{11.819999694824219, 12.039999961853027, 12.09000015258789,
11.880000114440918, 12.430000305175781}, "Real32"], {}, None},
"ElementType" -> "Real32"]]}}]]]]];Import a SAS7BDAT file as an EventSeries :
Import[file, "EventSeries"]"LabeledData" (1)
Import a SAS7BDAT file as an association of labels and data:
Import["ExampleData/sample.sas7bdat", "LabeledData"]"LabeledRawData" (1)
Import a SAS7BDAT file as an association of labels and raw data:
Import["ExampleData/sample.sas7bdat", "LabeledRawData"]"Tabular" (1)
Import a SAS7BDAT file as a Tabular :
Import["ExampleData/sample.sas7bdat", "Tabular"]"TimeSeries" (1)
Export a Tabular object to a SAS7BDAT file:
file = Export["test.sas7bdat", Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Date" -> Association["ElementType" -> TypeSpecifier["Date"]["Integer32", "Day",
"Gregorian", 0]], "Value" -> Association["ElementType" -> "Real32"]],
"KeyColumns" -> None, "Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {5, {{NumericArray[{13150, 13151, 13152, 13153, 13156},
"Integer32"], {}, None}}, None}, "ElementType" -> "Date"["Integer32", "Day",
"Gregorian", 0]]], TabularColumn[Association["Data" ->
{NumericArray[{11.819999694824219, 12.039999961853027, 12.09000015258789,
11.880000114440918, 12.430000305175781}, "Real32"], {}, None},
"ElementType" -> "Real32"]]}}]]]]];Import a SAS7BDAT file as a TimeSeries :
Import[file, "TimeSeries"]Data Descriptors (4)
"ColumnDescriptions" (1)
Import associations giving the name, description and type for each column in a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "ColumnDescriptions"]"ColumnLabels" (1)
Import the names of each column in a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "ColumnLabels"]"ColumnTypes" (1)
Import the types of each column in a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "ColumnTypes"]"MissingPositions" (1)
Import associations giving the positions of missing values by column:
Import["ExampleData/sample.sas7bdat", "MissingPositions"]Metadata (9)
"ByteOrdering" (1)
Import the byte ordering stored in the metadata of a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "ByteOrdering"]"CharacterEncoding" (1)
Import the character encoding stored in the metadata of a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "CharacterEncoding"]"Comments" (1)
Import comments stored in the metadata of a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "Comments"]"CreationDate" (1)
Import the creation date:
Import["ExampleData/sample.sas7bdat", "CreationDate"]"Dimensions" (1)
Import the data dimensions:
Import["ExampleData/sample.sas7bdat", "Dimensions"]"MetaInformation" (1)
Import an association of all the metadata stored in a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "MetaInformation"]"ModificationDate" (1)
Import the modification date:
Import["ExampleData/sample.sas7bdat", "ModificationDate"]"TableName" (1)
Import the table name stored in the metadata of a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "TableName"]"Version" (1)
Import the version of a SAS7BDAT file:
Import["ExampleData/sample.sas7bdat", "Version"]Import Options (3)
"ColumnDefaultValues" (1)
Missing numerical values are replaced with zero by default:
Normal[Lookup[Import["ExampleData/sample.sas7bdat", "LabeledRawData"], {"Missing", "MissingTagged"}]]//Function[...]Use "ColumnDefaultValues" to specify a different default value for specific columns:
Normal[Lookup[Import["ExampleData/sample.sas7bdat", "LabeledRawData", "ColumnDefaultValues" -> <|"Missing" -> -1., "MissingTagged" -> -10.|>], {"Missing", "MissingTagged"}]]//Function[...]"TimeColumn" (1)
Export a Tabular object to a SAS7BDAT file:
file = Export["test.sas7bdat", Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Date" -> Association["ElementType" -> TypeSpecifier["Date"]["Integer32", "Day",
"Gregorian", 0]], "Value" -> Association["ElementType" -> "Real32"]],
"KeyColumns" -> None, "Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {5, {{NumericArray[{13150, 13151, 13152, 13153, 13156},
"Integer32"], {}, None}}, None}, "ElementType" -> "Date"["Integer32", "Day",
"Gregorian", 0]]], TabularColumn[Association["Data" ->
{NumericArray[{11.819999694824219, 12.039999961853027, 12.09000015258789,
11.880000114440918, 12.430000305175781}, "Real32"], {}, None},
"ElementType" -> "Real32"]]}}]]]]];By default, the time column is selected automatically for "TimeSeries" and "EventSeries" elements:
Import[file, "TimeSeries"]Use the "TimeColumn" option to specify the time column:
Import[file, "TimeSeries", "TimeColumn" -> "Value"]"TypeDefaultValues" (1)
Missing numerical values are replaced with zero by default:
Normal[Lookup[Import["ExampleData/sample.sas7bdat", "LabeledRawData"], {"Missing", "MissingTagged"}]]//Function[...]Use "TypeDefaultValues" to specify a different default value for specific types:
Normal[Lookup[Import["ExampleData/sample.sas7bdat", "LabeledRawData", "TypeDefaultValues" -> <|"Real64" -> -1.|>], {"Missing", "MissingTagged"}]]//Function[...]Export Options (2)
"ColumnDescriptions" (1)
Export different data types:
Export["test.sas7bdat", {{1, 2., "3"}, {4, 5., "6"}}]Columns will automatically infer types based on the data given:
Import["test.sas7bdat", "ColumnDescriptions"]Use "ColumnDescriptions" to specify column types and descriptions:
Export["test.sas7bdat", {{1, 2., "3"}, {4, 5., "6"}}, "ColumnDescriptions" -> {<|"Type" -> "String", "Description" -> "String data."|>}]Import the resulting column descriptions:
Import["test.sas7bdat", "ColumnDescriptions"]"MetaInformation" (1)
Retrieve the metainformation from a SAS7BDAT file:
meta = Import["ExampleData/sample.sas7bdat", "MetaInformation"]Export a new file with the same metainformation:
Export["test.sas7bdat", {{1, 2, 3}, {4, 5, 6}}, "MetaInformation" -> meta]Import["test.sas7bdat", "MetaInformation"]History
Introduced in 2021 (12.3) | Updated in 2021 (13.0) ▪ 2025 (14.2) ▪ 2026 (15.0)