DIVERSE REPORT GENERATION

advertisement
DIVERSE REPORT GENERATION
By Chris Speck
PAREXEL International
Durham, NC
Introduction
• Diverse Report Generation (DRG)
– A dynamic way to produce listings or patient profiles
– A new way of thinking about report generation
• DRG Goals
– Automation of large reporting jobs in one macro with minimal
code
– Synthesis of multiple and disparate datasets
– 1-step updates for adding or removing outputs
– Easy portability between projects
– Potential for expansion of capabilities
Alternative Ways of Reporting
• Suppose we need to produce patient profile
documents with data from 4 datasets.
• Intuitive: Loop through a macro using Brute Force
– Difficult to edit, especially for large jobs
– Difficult to transport across studies
– Prone to bugs
Alternative Ways of Reporting
• Loop through a macro using macro logic
LISTING MACRO USING MACRO LOGIC
Get/Derive
dataset List
More
datasets
?
YES
NO
ADMH?
YES
NO
PROC REPORT
Data=ADMH
ADAE
?
YES
PROC REPORT
Data=ADAE
NO
ADVS
?
YES
PROC REPORT
Data=ADVS
– Same difficulties as previous example
NO
NO
ADEG
?
YES
PROC REPORT
Data=ADEG
DRG Method of Reporting
• Call %MakeReport macro which has only one
PROC REPORT and writes code at run time
• To update program, need only to add new
macro calls not new PROC REPORTS
PATIENT PROFILES MACRO USING DRG
Get/Derive
Patient List
More
Patients
?
YES
%MakeReport
Macro Call:
ADMH
%MakeReport
Macro Call:
ADAE
%MakeReport
Macro Call:
ADVS
NO
MAKE REPORT MACRO
%MakeReport
Macro Call:
ADEG
DRG Method of Reporting
• How can DRG possibly do this:
– with only one PROC REPORT?
– while avoiding lengthy macro logic?
– With datasets having differing numbers of variables?
• Column statements would differ across datasets.
• The number of define statements would differ across
datasets.
• The width of columns would be different for each dataset.
DRG Method of Reporting
• Five steps:
1. Subsetting data
2. Adding blank observation to
datasets if necessary
3. Capturing metadata (variables,
labels) from SASHELP.VTABLE
4. Building DEFINE statements into
a PROC SQL macro variable
5. Inserting DEFINE macro variable
into PROC REPORT
• PARAMETERS
–
–
–
–
–
–
Dataset name
Variable list
Where statement
Column widths
Autofit flag
Titles and headers
Macro Call Example
• Note that parameters and their values are arbitrary
Macro Call Example
Optional
Parameters
Part of Patient List mentioned
on Slides 3 and 4
• Note that parameters and their values are arbitrary
Steps 1-3
• Establish macro variables
– &DEFINE becomes PROC REPORT define statements
– &EMPTY tells PROC REPORT if any observations met
the WHERE criteria. Default is N.
– &LS resolves to Line Size. For this example, &LS=125.
• Subset data with WHERE parameter
• Insert blank observation if dataset is empty
– &EMPTY is assigned here. Y if no observations meet
WHERE criteria
Step 1: Subset Data
• The Code:
Step 1: Subset Data
• The Code:
Common sense
dataset suffix
Keep only variables
parameter list
RETAIN sorts
variables
according to
parameter list
WHERE parameter
subsets data
Step 2: Insert Blank Row
• Insert empty observation into &DS.RPT0 if
dataset is empty so PROC REPORT can read it.
Step 2: Insert Blank Row
• Insert empty observation into &DS.RPT0 if
dataset is empty so PROC REPORT can read it.
Temporary variable equal to
number of observations
Step 2: Insert Blank Row
• Insert empty observation into &DS.RPT0 if
dataset is empty so PROC REPORT can read it.
Temporary variable equal to
number of observations
Takes us to MODIFY
with no change
Step 2: Insert Blank Row
• Insert empty observation into &DS.RPT0 if
dataset is empty so PROC REPORT can read it.
Temporary variable equal to
number of observations
Takes us to MODIFY
with no change
Takes us to MODIFY
with changes
Step 2: Insert Blank Row
• Insert empty observation into &DS.RPT0 if
dataset is empty so PROC REPORT can read it.
Temporary variable equal to
number of observations
Takes us to MODIFY
with no change
Takes us to MODIFY
with changes
Modifies dataset without having to read it into the
PDV. Hence no SET statement
Step 3: Capturing Metadata
• The Code:
Step 3: Capturing Metadata
• The Code:
Macro logic used because WIDTH
and AUTOFIT are optional
Step 3: Capturing Metadata
• &DS.RPT1 should look something like this:
NAME
LABEL
WIDTH
MHCAT
Category for Medical History
20
MHTERM Reported Term for Medical
History
30
MHPTT
30
Preferred Term for Medical
History
MHSTDAT Start Date
20
MHONGO Ongoing?
10
What was
horizontal is
now vertical
What would
WIDTH be if
AUTOFIT=Y?
Step 4: Building DEFINE Statements
• The Code:
Step 4: Building DEFINE Statements
• The Code:
Using SELECT and INTO to build
macro variable called DEFINE. This
becomes PROC REPORT code.
Semi-colon
ends each SAS
statement.
Step 4: Building DEFINE Statements
• The Code if using ODS RTF:
Use STYLE statements
and percents instead of
absolute widths
Step 4: Building DEFINE Statements
• &DEFINE should ultimately look something
like this:
Step 5: Produce Reports
• The Code:
Step 5: Produce Reports
• The Code:
Inserting variable list,
title and header
parameters
Inserting &DEFINE macro
variable as PROC REPORT code
Using &EMPTY to provide
notice if no observations
match WHERE criteria
Error Checking Examples
• Do datasets and variables exist?
• Do number of values in WIDTHS and VARS
parameters match?
• Is sum of WIDTH values and appropriate
spacing values ≤ &LS?
• Are WIDTHS and AUTOFIT parameters
populated at the same time?
Final Thoughts on DRG
• Datasets must be pre-programmed, sorted, and
ready for reporting
• Best for profile, listing, or similar reporting in
which data has little treatment in PROC REPORT
• Not best approach if using complex COMPUTE
blocks or PROC REPORT to alter data
• BY, GROUP, ORDER, and BREAK statements can
be introduced through additional parameters
Conclusion
• DRG is an alternative brute force and macro
logic automation
• DRG allows for shorter programming times,
more elegant and transportable code
• By having SAS write code for us, DRG is an
effective way to utilize the power of SAS
CONTACT INFORMATION
Chris Speck
Principal Programmer
PAREXEL International, Durham, NC
chris.speck@parexel.com
Download