Pandas can read two file formats from SAS – SAS xports (.XPT) and SAS data files (.sas7bdat).
The read_sas() function helps read SAS files. Here, a SAS data file has been read and displayed as a pandas dataframe:
df = pd.read_sas('sample.sas7bdat')
df
This results in the following output:
![](https://static.packt-cdn.com/products/9781789343236/graphics/assets/83cb9f2b-0d6c-428a-bde7-f4e3ebaa063e.png)
Output of read_sas
The chunksize and iterator arguments help in reading the SAS file in groups of the same size. If the SAS data file that was used earlier is read with a chunksize of 10, then the 51 records will be divided into six groups, as shown in the following code:
rdr = pd.read_sas('sample.sas7bdat', chunksize=10)
for chunk in rdr:
print(chunk.shape)
Take a look at the following output:
![](https://static.packt-cdn.com/products/9781789343236/graphics/assets/b71ebc09-1929-443e-bdf7-1a75cf72d09c.png)
Output of read_sas with chunksize
However, these SAS files cannot be written using pandas.
Pandas also provides support for reading and writing files...