reporting scheduling errors - sas institute · presented to the edmonton sas user group april 5,...

29
Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Upload: others

Post on 17-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Presented to the

Edmonton SAS User Group

April 5, 2016

By John Fleming

Reporting Scheduling Errors

Page 2: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

The code you are about to see is real. Only the places, parameters and data have been

changed to protect the innocent.

Page 3: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Where I work, data quality is very important.

To support this, we developed a monthly report showing the trend in data entry errors over the preceding 13 months.

Page 4: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

For today’s presentation, I will be looking at modified version of the code used to create the actual report.

Instead of my organization’s data, I will be using fictitious data with error rates designed to demonstrate the features of the program using a non-existent organization providing services of some kind to people living in Finland.

I’ve also replaced our logo with a happy face.

Page 5: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

South Area

• Espoo Center (EC)• Helsinki Center (HC)• Lahti Center (LC)

Central Area

• Joensuu Center (JC)• Kuopio Center (KC)• Mikkeli Center (MC)• Pori Center (PC)

North Area

• Oulu Center (OC)• Rovaniemi Center (RC)

Nine Sites In Three Geographic Areas

Page 6: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Error Data For The Report

Page 7: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Page 1 Graph Produced WithPROC SGPLOT

Page 2 Table Produced WithPROC REPORT

The Report Has Two Pages

Page 8: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

“The SG Procedures provide a direct procedure interface into the ODS Graphics system. These procedures create graphs with very little code.”

Matange, Sanjay and Dan Heath, 2011, Statistical Graphics Procedures by Example: Effective Graphics Using SAS®, Cary, NC: SAS Institute Inc. p. 19

Why Statistical Graphics (SG) Procedures?

Page 9: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

When we developed this program, we wanted something that could do the job with the minimum of human intervention.

For that reason, we used macro variables to control features of the report that change every month.

Macro Variables For Automation

Page 10: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

One macro variable controls the report creation date that appears on the report.

&today1 - run date in the form yyyy-mmm-dd e.g., 2016-Feb-15)

Macro Variables For Automation

Page 11: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Two macro variables control the date tag in the name of the output PDF file.

&vuosi - year for last month of data in the report in the form yyyy (e.g., 2016)

&kuukusi - month for last month of data in the report in the form mm (e.g., 01)

For example, “file_name_2016_01.pdf”

Macro Variables For Automation

Page 12: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

One macro variable, &mpath, controls the pathname for the output.

For example, Z:\trend reports\2016\

Macro Variables For Automation

Page 13: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Two macro variables control the start and end dates shown in the report title.

&sdate - start date for report title in the form “monthname day, year”(e.g., January 1, 2015 )

&edate - end date for report title in the form “monthname day, year”(e.g., January 31, 2016)

Macro Variables For Automation

Page 14: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Two macro variables control the start and end year and month for the data to appear in the report.

&firstflag - earliest value of the dateflag variable in the form yyyymm (e.g., 201501)

&lastflag - latest value of the dateflag variable in the form yyyymm (e.g., 201601)

Macro Variables For Automation

&firstflag

&lastflag

Page 15: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

%trheader – creates the report title and controls the report layout

%trfooter – creates a boilerplate report footer (omitted for this presentation)

%oback – controls the traffic lighting on the table produced with PROC REPORT

Macro Functions For Automation

Page 16: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

1. Prepare the SAS environment2. Define output title and report layout 3. Create the graph4. Define the output footer (omitted for this presentation)5. Define output title and report layout (again)6. Create the table7. Define the output footer (omitted again)8. Clean up

Steps To Creating The Report

Page 17: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

* Suppress SAS generated date and page number from being printed at top of page;

options nodate nonumber papersize=letter;

* Define escape character to indicate to ODS that an inline style format is about to start ;

ods escapechar = "^";

* Close other ODS destinations.;

ods _ALL_ close;

* Provide the pathname and file name for the output PDF document.;

ods pdf file= "&mpath.\Scheduling QA_Trend_Report_&vuosi._&kuukausi..pdf" nogfootnote nogtitle notoc dpi=300 ;

Note: this can be done anywhere in the program before the report title macro (%trheader) is called.

Prepare SAS Environment

Page 18: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Each Output Report Page Has Three Regions

This region contains the report title and is defined in the %trheader macro.

This region contains the graph (page 1) or the table (page 2) and is also

defined in the %trheader macro.

This region contains a boilerplate report footer and is defined in the %trfootermacro (omitted for this presentation).

Page 19: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Page 1 - The Graph

Page 20: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

%macro trheader;

title;

ods layout start;

ods region x=0pct y=0pct width=100pct height=20pct;

ods pdf text="^{style[preimage='T:\work\JohnF\Pres Under Dev\H_Face.gif' ]}" ;

ods pdf text="^S={just=r fontsize=11pt} &today1";

ods pdf text="^S={just=r fontsize=11pt} Page ^{thispage}";

ods pdf text="^S={just=c fontsize=16pt font_weight=bold} Non-existent Finnish Organization Scheduling Data Quality Trend Report";

ods pdf text="^S={just=c fontsize=14pt} Scheduled Appointments for the Period &sdate, to &edate";

ods pdf text="^S={just=c fontsize=14pt} * * * THIS REPORT CREATED USING FAKE DATA - DO NOT USE * * *";

ods region x=0pct y=20pct width=100pct height=59pct;

ods graphics on / scale=yes border=on width=8in height=5.75in;

%mend trheader;

“ODS Layout” allows us to customize the page layout.First “ODS Region” defines the area on the page for the report title.

Second “ODS Layout” defines the area on the page for the graph and table.“ODS Graphics” enables ODS graphics system.

Output Title And Report Layout

“ODS PDF Text” statements create the report title.

Page 21: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

%TRHEADER;

proc sgplot data=moog (where=("&firstflag" <= dateflag <= "&lastflag"));

series x=xlab y=ec / markers markerattrs=(symbol=circlefilled color="cxc91111") lineattrs=(color="cxc91111"); /* Crayola Red */

series x=xlab y=lc / markers markerattrs=(symbol=squarefilled color="cx0070FF") lineattrs=(color="cx0070FF"); /* Crayola Baby Blue */

[EIGHT MORE “SERIES” STATEMENTS]

refline 0.05 / label='Data Quality Target (5%)';

xaxis label='Year And Month';yaxis label='Percent of Row Frequency' offsetmax=0.1;

run;

%TRFOOTER;

ods pdf startpage=now;

%TRHEADER;

“ODS PDF Startpage” statement ensures graph and table are on different pages.

“Series” statements create and controls appearance of each line on the graph.

“Refline” statement adds the horizontal line showing the data quality target..

Page 22: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Page 2 - The Table

Page 23: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

proc report data=moog (where=("&firstflag" <= dateflag <= "&lastflag")) nowd split='*' style(column header)=[background=white] style(report)={rules=none font_size=10}style(header)=header{background=white rules=none};

columns sienna ('Year*And*Month' xlab) (‘North Area' oc rc) (‘Central Area' jc kc mc pc) (‘South Area' ec hc lc) (‘Average*Error*Rate' avg_error);

define sienna / display noprint;define xlab / display ' ' width=15 center;define oc / display width=10 center;

[NINE MORE DEFINE STATEMENTS]

compute xlab; if sienna=1 then do;

CALL DEFINE("xlab", "STYLE", "STYLE=[BACKGROUND=#DCDCDC]");end;

endcomp;

%oback (octr=oc);%oback (octr=rc);

[EIGHT MORE %OBACK CALLS]

run;

Page 24: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

%macro oback (octr=);compute &octr;

if sienna=1 then do;if &octr > 0.05 then do;

CALL DEFINE("&octr", "STYLE", "STYLE=[BACKGROUND=cbackx. fontweight=bold]");end;else do;

CALL DEFINE("&octr", "STYLE", "STYLE=[BACKGROUND=cbackx.]");end;

end;else do;

if &octr > 0.05 then do;CALL DEFINE("&octr", "STYLE", "STYLE=[BACKGROUND=cback. fontweight=bold]");

end;else do;

CALL DEFINE("&octr", "STYLE", "STYLE=[BACKGROUND=cback.]");end;

end;endcomp;

%mend oback;

%oback macro function for cell formatting

Want the text to be bold when errors exceed a threshold.

Use STYLE attribute with a format to control background color.

Sienna controls table row format.

We use a different format for rows where sienna not equal to 1.

Page 25: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

proc format;

value cback. = "white"low - 0.05 = "white"0.05 <- 0.10 = "cxFED85D" /* Crayola Canary */0.10 <- high = "cxFE6F5E"; /* Crayola Bittersweet */

value cbackx. = "cxDCDCDC"low - 0.05 = "cxDCDCDC" /* One of fifty shades of grey */0.05 <- 0.10 = "cxFED85D" /* Crayola Canary */0.10 <- high = "cxFE6F5E"; /* Crayola Bittersweet */

run;

Formats For Traffic Lighting

This can be done anywhere in the program before the PROC REPORT code for the table on report page 2.

Page 26: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

* Need a quick n dirty data set for the legend under the table.;

data fnote;

sienna = 0;box = 'x';boxtext = 'Error rate greater than 5% but less than 10%.';output;

sienna = 1;box = 'x';boxtext = 'Error rate of 10% or greater.';output;

run;

For Legend, Need An Extra Data Set

Create this data set any time before the table legend on page 2 of the report is created.

Sienna controls table row format.

Page 27: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

proc report data=fnote nowdstyle(report)={rules=none font_size=10};

column sienna (' ' box) box2 (' ' boxtext);

define sienna / display ' ' noprint;define box / display ' ' width=10;define box2 / computed ' ' noprint ;define boxtext / display ' ';

compute box2;box2 = ' ';

if sienna=0 then do;CALL DEFINE("box", "STYLE", "STYLE=[BACKGROUND=cxFED85D FOREGROUND=cxFED85D]"); /* Crayola Canary */

end;else if sienna=1 then do;

CALL DEFINE("box", "STYLE", "STYLE=[BACKGROUND=cxFE6F5E FOREGROUND=cxFE6F5E]"); /* Crayola Bittersweet */

end;endcomp;

run;

This PROC REPORT creates the legend beneath the table with the data.

Page 28: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

* Close ODS PDF destination and reset other ODS destinations.;

ods pdf close; ods listing; ods graphics off;

Clean Up

Page 29: Reporting Scheduling Errors - Sas Institute · Presented to the Edmonton SAS User Group April 5, 2016 By John Fleming Reporting Scheduling Errors

Questions?!