DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

30
DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC

Transcript of DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Page 1: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

DIVERSE REPORT GENERATION

By Chris SpeckPAREXEL International

Durham, NC

Page 2: 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

Page 3: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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

Page 4: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Alternative Ways of Reporting• Loop through a macro using macro logic

– Same difficulties as previous example

PROC REPORTData=ADMH

PROC REPORTData=ADAE

YES

NO

LISTING MACRO USING MACRO LOGIC

Get/Derive dataset List

Moredatasets

?

ADMH?

YES

NO ADAE?

YES

NO

PROC REPORTData=ADVS

ADVS?

YES

ADEG?

YES

NO

NO

PROC REPORTData=ADEG

Page 5: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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

YES

NO

PATIENT PROFILES MACRO USING DRG

Get/Derive Patient List

MorePatients

?

MAKE REPORT MACRO

%MakeReport Macro Call:

ADMH

%MakeReport Macro Call:

ADAE

%MakeReport Macro Call:

ADVS

%MakeReport Macro Call:

ADEG

Page 6: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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.

Page 7: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

DRG Method of Reporting• Five steps:

1. Subsetting data2. Adding blank observation to

datasets if necessary3. Capturing metadata (variables,

labels) from SASHELP.VTABLE4. Building DEFINE statements into

a PROC SQL macro variable5. Inserting DEFINE macro variable

into PROC REPORT

• PARAMETERS– Dataset name– Variable list– Where statement– Column widths – Autofit flag– Titles and headers

Page 8: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Macro Call Example

• Note that parameters and their values are arbitrary

Page 9: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Macro Call Example

• Note that parameters and their values are arbitrary

Part of Patient List mentioned on Slides 3 and 4

Optional Parameters

Page 10: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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

Page 11: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 1: Subset Data• The Code:

Page 12: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 1: Subset Data• The Code: Common sense

dataset suffixKeep only variables

parameter list

RETAIN sorts variables

according to parameter list

WHERE parameter subsets data

Page 13: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 2: Insert Blank Row• Insert empty observation into &DS.RPT0 if

dataset is empty so PROC REPORT can read it.

Page 14: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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

Page 15: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 2: Insert Blank Row• Insert empty observation into &DS.RPT0 if

dataset is empty so PROC REPORT can read it.

Takes us to MODIFY with no change

Temporary variable equal to number of observations

Page 16: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 2: Insert Blank Row• Insert empty observation into &DS.RPT0 if

dataset is empty so PROC REPORT can read it.

Takes us to MODIFY with no change

Takes us to MODIFY with changes

Temporary variable equal to number of observations

Page 17: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 2: Insert Blank Row• Insert empty observation into &DS.RPT0 if

dataset is empty so PROC REPORT can read it.

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

Temporary variable equal to number of observations

Page 18: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 3: Capturing Metadata

• The Code:

Page 19: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 3: Capturing Metadata

• The Code:Macro logic used because WIDTH

and AUTOFIT are optional

Page 20: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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 Preferred Term for Medical History

30

MHSTDAT Start Date 20

MHONGO Ongoing? 10

What was horizontal is now vertical

What would WIDTH be if AUTOFIT=Y?

Page 21: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 4: Building DEFINE Statements

• The Code:

Page 22: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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.

Page 23: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 4: Building DEFINE Statements

• The Code if using ODS RTF:

Use STYLE statements and percents instead of

absolute widths

Page 24: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 4: Building DEFINE Statements

• &DEFINE should ultimately look something like this:

Page 25: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

Step 5: Produce Reports

• The Code:

Page 26: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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

Page 27: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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?

Page 28: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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

Page 29: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

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

Page 30: DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.

CONTACT INFORMATION

Chris SpeckPrincipal ProgrammerPAREXEL International, Durham, [email protected]