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:
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:
Output of read_sas with chunksize
However, these SAS files cannot be written using pandas.
Pandas also provides support for reading and writing files...