XPORT (.stx, .xpt)
Background & Context
-
- MIME type: application/x-sas-xport
- SAS XPORT transport format.
- Legacy data exchange format.
- Stores numerical datasets in a portable format.
- Text format.
- Developed in the late 1980s by SAS Institute.
Import & Export
- Import ["file.xpt"] imports an XPORT file, returning all datasets arranged as a table.
- XPORT data is represented in the Wolfram Language by real or integer numbers, strings, Boolean values True and False , and DateObject specifications.
- Import ["file.xpt",elem] imports the specified element from an XPORT file.
- Import ["file.xpt",{elem,suba,subb,…}] imports a subelement.
- The import format can be specified with Import ["file","XPORT"] or Import ["file",{"XPORT",elem,…}].
- Export ["file.xpt",expr] creates an XPORT 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 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"Rules" list of rules for all available elements"Summary" summary of properties
- 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 an XPORT file:
Import["ExampleData/sample.xpt"]Summary of an XPORT file:
Import["ExampleData/sample.xpt", "Summary"]Export an array of expressions to an XPORT file:
file = Export["test.xpt", {{"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:
Import[file, "Tabular"]Scope (9)
Import (3)
Import all available elements:
Import["ExampleData/sample.xpt", "Elements"]Import data:
Import["ExampleData/sample.xpt", "Data"]Import as a Tabular object:
Import["ExampleData/sample.xpt", "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.xpt", dataset];Column names are automatically inferred:
Import[file, "Dataset"]Export an array of data:
file = Export["test.xpt", {{1, 2, 3}, {4, 5, 6}}]Column names are automatically generated:
Import[file, "Dataset"]Export an association of named columns:
file = Export["test.xpt", <|"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.xpt", ts]Times are stored in the first column, values in the second:
Import[file, "Dataset"]Export tagged missing data:
file = Export["test.xpt", {{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.xpt", {a, {d, e, f}}]Import[file, "Dataset"]Import Elements (18)
Data Representation (7)
"Data" (1)
Import an XPORT file as a 2D list of values:
Import["ExampleData/sample.xpt", "Data"]This is also the default element:
Import["ExampleData/sample.xpt"]"Dataset" (1)
Import an XPORT file as a Dataset :
Import["ExampleData/sample.xpt", "Dataset"]"EventSeries" (1)
Export a Tabular object to an XPORT file:
file = Export["test.xpt", 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 an XPORT file as an EventSeries :
Import[file, "EventSeries"]"LabeledData" (1)
Import an XPORT file as an association of labels and data:
Import["ExampleData/sample.xpt", "LabeledData"]"LabeledRawData" (1)
Import an XPORT file as an association of labels and raw data:
Import["ExampleData/sample.xpt", "LabeledRawData"]"Tabular" (1)
Import an XPORT file as a Tabular :
Import["ExampleData/sample.xpt", "Tabular"]"TimeSeries" (1)
Export a Tabular object to an XPORT file:
file = Export["test.xpt", 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 an XPORT file as a TimeSeries :
Import[file, "TimeSeries"]Data Descriptors (4)
"ColumnDescriptions" (1)
Import associations giving the name, description and type for each column in an XPORT file:
Import["ExampleData/sample.xpt", "ColumnDescriptions"]"ColumnLabels" (1)
Import the names of each column in an XPORT file:
Import["ExampleData/sample.xpt", "ColumnLabels"]"ColumnTypes" (1)
Import the types of each column in an XPORT file:
Import["ExampleData/sample.xpt", "ColumnTypes"]"MissingPositions" (1)
Import associations giving the positions of missing values by column:
Import["ExampleData/sample.xpt", "MissingPositions"]Metadata (7)
"Comments" (1)
Import comments stored in the metadata of an XPORT file:
Import["ExampleData/sample.xpt", "Comments"]"CreationDate" (1)
Import the creation date:
Import["ExampleData/sample.xpt", "CreationDate"]"Dimensions" (1)
Import the data dimensions:
Import["ExampleData/sample.xpt", "Dimensions"]"MetaInformation" (1)
Import an association of all the metadata stored in an XPORT file:
Import["ExampleData/sample.xpt", "MetaInformation"]"ModificationDate" (1)
Import the modification date:
Import["ExampleData/sample.xpt", "ModificationDate"]"TableName" (1)
Import the table name stored in the metadata of an XPORT file:
Import["ExampleData/sample.xpt", "TableName"]"Version" (1)
Import the version of an XPORT file:
Import["ExampleData/sample.xpt", "Version"]Import Options (3)
"ColumnDefaultValues" (1)
Missing numerical values are replaced with zero by default:
Normal[Lookup[Import["ExampleData/sample.xpt", "LabeledRawData"], {"Missing", "MissingTagged"}]]//Function[...]Use "ColumnDefaultValues" to specify a different default value for specific columns:
Normal[Lookup[Import["ExampleData/sample.xpt", "LabeledRawData", "ColumnDefaultValues" -> <|"Missing" -> -1., "MissingTagged" -> -10.|>], {"Missing", "MissingTagged"}]]//Function[...]"TimeColumn" (1)
Export a Tabular object to an XPORT file:
file = Export["test.xpt", 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.xpt", "LabeledRawData"], {"Missing", "MissingTagged"}]]//Function[...]Use "TypeDefaultValues" to specify a different default value for specific types:
Normal[Lookup[Import["ExampleData/sample.xpt", "LabeledRawData", "TypeDefaultValues" -> <|"Real64" -> -1.|>], {"Missing", "MissingTagged"}]]//Function[...]Export Options (2)
"ColumnDescriptions" (1)
Export different data types:
Export["test.xpt", {{1, 2., "3"}, {4, 5., "6"}}]Columns will automatically infer types based on the data given:
Import["test.xpt", "ColumnDescriptions"]Use "ColumnDescriptions" to specify column types and descriptions:
Export["test.xpt", {{1, 2., "3"}, {4, 5., "6"}}, "ColumnDescriptions" -> {<|"Type" -> "String", "Description" -> "String data."|>}]Import the resulting column descriptions:
Import["test.xpt", "ColumnDescriptions"]"MetaInformation" (1)
Retrieve the metainformation from an XPORT file:
meta = Import["ExampleData/sample.xpt", "MetaInformation"]Export a new file with the same metainformation:
Export["test.xpt", {{1, 2, 3}, {4, 5, 6}}, "MetaInformation" -> meta ]Import["test.xpt", "MetaInformation"]History
Introduced in 2007 (6.0) | Updated in 2021 (12.3) ▪ 2021 (13.0) ▪ 2025 (14.2) ▪ 2026 (15.0)