Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
'C to the Power of 3': Utilizing SAS to Connect, Create and Collaborate for Complete(?)
Report Automation
Roushain Akhter, Manitoba [email protected]
October 25, 2013
1
Overview
• Background
• 'C to the Power of 3'
– Connect
– Create
– Collaborate
• Examples
• References
2
Background
• Manitoba Health Initiatives:
– Electronic Medical Records (EMR) Adoption Program
– Chronic Disease Management
– Physician Integrated Network
• Utilizing SAS
– What are we trying to achieve?
– Why and how SAS?
3
• Connect:– Using SAS to connect an external data source. e.g.,
Oracle/ Access database.
• Create:– Use PROC SQL to manipulate data.– Build Excel template and name ranges.– LIBNAME command to access the template and
populate report data.– Save reports into a permanent folder with the current
date.
• Collaborate:– Email report to the recipients.
4
'C to the Power of 3'
Connect
Things to consider for SAS connections:
• SAS/ ACCESS license
• Via ODBC connect
• Ways to connect
– PROC IMPORT
– LIBNAME statement
– SQL Pass-Through
5
Connect (cont.)
1) PROC IMPORT
6
PROC IMPORT OUT= WORK.FormDetails
DATATABLE= “FormDetials"
DBMS=ACCESS REPLACE;
DATABASE=“D:\CDM_tariff.accdb";
SCANMEMO=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
2) LIBNAME statement• Connect a PC file format database:
• Connect a client server database:
7
LIBNAME oraconn odbc dsn=dsn_name uid=scott pwd=tiger; /*IF you would like to avoid the hardcoded user name and password then you may use
the method below or use PROC PWENCODE to create an encrypted value and/or pass as a
macro variable input.*/
LIBNAME oradata odbc dsn=dsn_name uid=&uid. pwd=&upass.
schema=EMRData;
/** %DISPLAY invokes the prompt **/ [Ref.HIM]
%window info
#5 @5 'Please enter your userid:'
#5 @40 uid 20 attr=underline
#7 @5 'Please enter your password:'
#7 @40 upass 20 attr=underline
%display info;
LIBNAME accDB ‘D:\CDM_tariff.accdb';
Connect (cont.)
Connect (cont.)
8
3) SQL Pass-Through:
PROC SQL <options> ;CONNECT TO ORACLE <AS alias> USER=ORACLE-user-namePASSWORD=ORACLE-passwordPATH="ORACLE-path-designation"BUFFSIZE=number-of-rowsPRESERVE_COMMENTS;<sql statements>DISCONNECT FROM ORACLE;QUIT;
• Query data and build your report using PROC SQL and/or DATA Step.
• Use LIBNAME function to access pre-formatted EXCEL template and populate the template with data captured.
• Use Excel name ranges to customize and access Excel columns in SAS.
• Move/copy the report into a permanent folder.
9
Create
Create (cont.)Query Data and build your report using PROC SQL and/or DATA Step:
10
/*SELECT DATA FROM MULTIPLE TABLES BY USING SQL JOIN AND BUILD REPORTS
BASED ON BUSINESS REQUIREMENTS*/
PROC SQL;
CREATE TABLE cdmdata AS
SELECT datacollection.*, formDetails.*
FROM datacollection
INNER JOIN formdetails
ON datacollection.id = formdetails.datacollectionid
ORDER BY formdetails.datacollectionid;
QUIT;
Business Requirements:
– Check supplementary information in the CDM forms and find out if the required test results were filled in as required or left blank.
– Check whether patients meet target of test result(s).
/* THIS PART IS FOR ACCESSING EXCEL TEMPLATE AND PUT DATA INTO THE PRE-
FORMATTED TEMPLATE, YOU MAY USE DATA STEPS OR PROC SQL TO COMPLETE THE TASK*/
LIBNAME xls EXCEL 'C:\temp\demo.xls' ver=2003;/* CLEAR VARIABLE*/
PROC datasets LIB = xls NOLIST;
DELETE rundate;
DELETE myrange;
QUIT;/* ASSIGN VALUE INTO A VARIABLE*/
DATA xls.rundate;
FORMAT Date_Report_Run yymmddd10.;
Date_Report_Run = today();
RUN;/* PLACE DATA INTO RANGE ASSIGNED*/
DATA xls.myrange;
SET work.rpt3;
RUN;/* CLEAR - RECOMMENDED*/
LIBNAME xls CLEAR;
11
Use LIBNAME function to access EXCEL template and populate:
12
PROC SQL:
proc sql noprint;
/*Update report title and other details within the title by using PROC SQL*/
update report.reportTitle
set
Value = "EMR Data Extract Error Details"
where Element = "Title";
/*Attach clinic name on the report title PROC SQL*/
update report.reportTitle
set
Value = "Clinic - &Clinicname. (" || put(¤tclinic.,z4.)
where Element = "Clinic";
/*Attach date received */
select max(DATE_RECIEVED) into: recieveDate from PINData.raw_data_archive x
where
x.clinic_ID = ¤tClinic.
and x.batch_ID = ¤tBatch.
group by clinic_id , batch_id;
/*And so on.. */
update report.reportTitle
set
dtValue = put(Date(),DATE9.)
where Element = "rundate"; /*[Ref. HIM] */
/*COPY REPORT INTO A PERMANENT FOLDER AND INCLUDE REPORT RUNDATE IN TITLE*/
%LET him=D:\Roushain\CDM\test;
OPTIONS NOXWAIT;
DATA _NULL_;
xcommand = "copy ""C:\temp\demo.xls"" ""&him.\DataQualityReport-&SYSDATE..xls""";
CALL system(xcommand);
RUN;
13
/* OR BUILD YOUR MACRO TO HAVE MORE CONTROL ON YOUR OUTPUT */
%Macro GetDateStamp(VariableName=_DateStamp);
%global &VariableName.;
%let dateYear=%qsysfunc(year(%qsysfunc(date())));
%let dateMonth=%qsysfunc(putn(%qsysfunc(Month(%qsysfunc(date()))),z2.));
%let dateDay=%qsysfunc(putn(%qsysfunc(Day(%qsysfunc(date()))),z2.));
%let &VariableName.=&dateYear.&DateMonth.&DateDay.;
%mend;
/* CALL MACRO by fdate */
%getdatestamp(VariableName = fdate);
DATA_NULL;
xcommand = "copy ""C:\temp\demo.xls""
"“D:\Roushain\CDM\test\ReportOverview - &fdate..xls""";
CALL system(xcommand);
RUN; /*[Ref. HIM] */
Copy the report into a permanent folder:
14
Sample output
15
Sample output:
Collaborate
• FILENAME statement with the EMAIL device-type keyword
• Options specified in the FILENAME or FILE statements indicating the e-mail recipients, subject, and any attached files
• PUT statements that contain the body of the message
• PUT statements that contain special e-mail directives (of the form !EM_directive!) that can override the e-mail attributes (TO, CC, BCC, SUBJECT, ATTACH) or perform actions (such as SEND, ABORT, and start a NEWMSG)
16
Collaborate (cont.)
FILENAME myemail EMAIL;
DATA _NULL_;
FILE myemail;
PUT "!EM_TO!" '[email protected]';
PUT "!EM_ATTACH!" '&him.\DataQualityReport-
&SYSDATE..xls';
PUT "!EM_SUBJECT! Data Quality Report-&SYSDATE";
PUT "!EM_IMPORTANCE! High";
PUT "Attached are the data quality reports for your
review as of &SYSDATE";
PUT " ";
PUT "Thanks!";
PUT "Roushain";
RUN;
FILENAME myemail CLEAR;
17
18
Sample output:
References
• Utilizing SAS® for Complete Report Automation, Brent D. Westra, http://www.mwsug.org/proceedings/2011/sas101/MWSUG-2011-S105.pdf
• Access to Relational Databases Using SAS ®, Frederick Pratter, http://www.pharmasug.org/psug2002/bp2002/tu01.pdf
• HIM Team: Craig Kasper, Nelson Prudencio, Roushain Akhter, Health Information Management, Manitoba Health
• Getting Started with SAS/Access for Oracle, F. Joseph Kelley, University of Georgia, http://analytics.ncsu.edu/sesug/2005/ETL05_05.PDF
• Customized Excel Output Using the Excel Libname, Harry Droogendyk, http://www.stratia.ca/papers/excel_libname.pdf
• E–mail from your SAS® Session: How and Why, David H. Johnson, http://www2.sas.com/proceedings/sugi31/256-31.pdf
• Optimizing Your SAS programs – Tips and Techniques, Craig Kasper, Manitoba Health http://www.sas.com/offices/NA/canada/downloads/presentations/Winnipeg-fall-11/Kasper-Optimization.pdf
19
Thank You!
20