1
SESUG 2020 Paper 140
TRANSFORM A SAS
®
DATASET TO AN EXCEL FILE FORMAT
Pravin vijay Varatharaj, Cognizant Technology Solutions
ABSTRACT
For many of us, using SAS
®
and Microsoft Excel together is unavoidable, it is often
necessary for a SAS
®
programmer to transform a SAS
®
dataset to an Excel file format.
Several methods for performing this transformation have been published in previous SAS
®
conference proceedings.
In windows, PC SAS
®
uses DDE (Dynamic Data Exchange) mechanism in SAS
®
enables
SAS
®
to control Excel template. This paper talks about how to transform a SAS
®
dataset to
an Excel template file format from the Linux server or Unix platform, Python language can
be used to transform the SAS
®
datasets to Excel template.
Python package like sas7bdat can be used to read the SAS
®
datasets and packages like
openpyxl can be used to write the content to the Excel template. Python language helps to
break the dependency of DDE communication mechanism to transform a SAS
®
dataset to an
Excel template file format and developers to schedule the jobs in the crontab to automate.
INTRODUCTION
This paper describes a custom Python function that transform a SAS
®
dataset to an Excel
template file format. The python function is driven by certain preset parameters which can
be overridden by the users.
This function can be used in batch programs as well as interactive Python sessions.
BACKGROUND AND ASSUMPTIONS
This paper assumes that users are familiar with the Python programing language
environment (i.e. reading SAS
®
dataset, working with Excel). The macro has been designed
for a Linux based system, but with some minor modifications, it can work in other
environments as well.
This code requires SAS
®
dataset which needs to be transformed and Excel template file.
TRANSFORM A SAS
®
DATASET TO AN EXCEL FILE FORMAT.
Python is open source and freely available for download. Many operating systems such as
Linux and Mac OS X (but not Windows) have it installed by default. Python is installed with a
standard library that contains several modules, some written in C, some in Python, each of
which addresses a unique functionality. Because Python is open source, community users
can also build their own modules and through code sharing repositories such as Git,
contribute them to the whole Python community. Additional packages not available with the
standard library can be downloaded. An import statement in the Python program then gives
access to its functionality. This transform SAS
®
Dataset to an excel format has various
advantages:
• You can use Python script (Sample Python script explained later in this paper) to
read SAS
®
datasets and export them to excel template.