Yes! We can auto-generate SAS codes from a SAS data set

advertisement
Robo-SAS Coding? Yes! We can
auto-generate SAS codes from a
SAS data set
By
Robert Williams
Senior Supply Chain Analyst
Strategic Sourcing and Contracts
The New York Times Company – Shared Service Center
Overview
Example PROC REPORT for Director
 Needs same reports for each manager by
dept ID
 Possible ways to generate reports by dept

◦ 1 – Copy and paste PROC REPORT codes for
each dept ID
◦ 2 – Use SAS macros with dept ID
◦ 3 – Dynamically generate PROC REPORTS
codes using dept ID variable (RoboCoding)

Q&A
Example of Directors Report
Director wants to know how many
minutes, data usage and text messaging
for all his employees by department.
 It is a PROC REPORT code to generate
the PDF report. See next slide for the
example.

Example of Directors Report
Same reports by Dept ID?
What if the Director wants to distribute
the same reports to every department
head?
 The Director wants it in separate PDF
reports for each department manager
responsible for their employees.

Separate PDF reports? How?
1 – We can copy and paste the PROC
REPORT codes and add the WHERE
statement for each department.
 2 – Or, we can use SAS macros that
includes the PROC REPORT codes and
use department ID as a marco variable.
 3 – Or, we can dynamically generate
PROC REPORT codes using dept ID from
a SAS data set (RoboCoding)

RoboCoding

Why do we need to dynamically generate
the SAS code by dept ID?
◦ With copy and paste or using SAS macros, we
have to get an exhaustive listing of all the
department IDs. This is ok if we have only a
few departments.
◦ But if we have about 100 departments,
dynamically generating the SAS code by dept
ID is the way to do this.
◦ If used as a monthly report, it may not have
the same groups of departments each month.
RoboCoding

Several key points how to dynamically
create SAS codes from SAS data sets
◦ Making a listing of all dept IDs using PROC
FREQ with output to SAS data set
◦ Use DATA _NULL_ to create a temporary
SAS program file
◦ In the DATA_NULL_ use ‘put’ statements to
include the PROC REPORT codes for each
line as well as the WHERE statements.
◦ Run the temporary SAS program file.
RoboCoding Sample Code
Q&A
Questions?
 Contact:
Robert Williams
The New York Times Company
Shared Service Center
101 West Main Street, Suite 2000
Norfolk,VA 23510
robert.williams@nytssc.com

References


SAS Certification Prep Guide: Base Programming for SAS 9 by SAS
Institute Inc. , Cary, NC.
SAS Online Doc Version 9.2. Cary, NC: SAS Institute Inc.
Download