pandas.read_sas

pandas 3.1.1 · Input and output · function

Load data from a SAS XPORT or SAS7BDAT file.

Call syntax

pd.read_sas(…) Full signature
pd.read_sas(
    filepath_or_buffer,
    *,
    format=None,
    index=None,
    encoding=…,
    chunksize=None,
    iterator=False,
    compression='infer',
)

Inspect the call

Run this code to inspect the callable and its parameters. Its data, backend, or environment is needed to execute the operation itself.

Parameters

ParameterRequirementAccepted values and behavior
filepath_or_buffer Required
Positional or keyword
str, path object, or file-like object
format Optional
Keyword only
Default None
str {'xport', 'sas7bdat'} or None

Supply a format string or choose an output layout supported by this API.

index Optional
Keyword only
Default None
identifier of index column

Supply row labels or control how existing row labels are used.

encoding Optional
Keyword only
str, 'infer' or None

Name a text encoding such as "utf-8".

chunksize Optional
Keyword only
Default None
int

Set how many rows to read or write in each batch.

iterator Optional
Keyword only
Default False
bool

Request an iterable reader so data can be consumed in pieces.

compression Optional
Keyword only
Default 'infer'
str or dict

Choose whether and how to compress or decompress data.

Returns

DataFrame, SAS7BDATReader, or XportReader

Example for a local Python session

import pandas as pd
# Replace the path with a SAS file on your computer.
orders = pd.read_sas("orders.sas7bdat", format="sas7bdat", encoding="utf-8")
print(orders.head(3))