Presentation is loading. Please wait.

Presentation is loading. Please wait.

Use SAS to Automate Hospital Reports generation Cardiac Service BC Stats Team, PHSA Tina Yang.

Similar presentations


Presentation on theme: "Use SAS to Automate Hospital Reports generation Cardiac Service BC Stats Team, PHSA Tina Yang."— Presentation transcript:

1 Use SAS to Automate Hospital Reports generation Cardiac Service BC Stats Team, PHSA Tina Yang

2 Hospital Reports Overview O A cross province quality assurance report focusing on clinical and performance indicators O 2 major reports for each of the 5 BC hospitals: Cathlab and Surgery O Surgery report as today’s example

3 Hospital Reports Challenges O Data Preview: O Large amount of information need to be disseminated O Each hospital has the same variables and metrics O Audience maybe senior management, data-entry clerks, who don’t know the story behind the data well O 5 hospitals, i.e. ~ 5 packages with distinct numbers, but in the same format, need to be created accurately and efficiently for each report

4 Excel Template for Surgery reports FMM Isolated CABG Waitlist Activities by Hospital (Time frame) Hospital Outpatient WaitlistInpatient WaitlistInpatient and Outpatient Waitlist Complete d Unbooked Cases Total Complete d Cases** Start Add Complete* Remove End Start Add Complete* Remove End Start Add Complete* Remove End Hosp 1 Hosp 2 Hosp 3 Hosp 4 Hosp 5 BC Example 1: Example 2: Open Heart Surgery Wait List from Hosp 1 (Time frame) Wait Time(Days) Surgeon Start Waitlist Numb er Added Completed from Waitlist Removed from Waitlist End Waitlist Median p90 Max Completed Unbooked/In- hospital Booking Cases Total Completed Cases Doctor 1 Doctor 2 Hosp 1 total

5 Possible Report Generation Methods O Excel VBA macro O Create an Excel workbook template for each sheet O Export prepared data from SAS into Excel O Call the VBA macro to populate the Excel template, one hospital/workbook at a time O Save the populated template with a distinct name for that corresponding hospital

6 Possible Report Generation Methods O Excel VBA macro O Pros O The reports will be automated in hospital-level O Can generate a set of Excel templates O Cons O Need to export data from SAS into Excel, which is not an analytical environment

7 Possible Report Generation Methods O Excelxp in SAS O Prepare data in SAS O Use proc tabulate and proc export to export data into Excel and format the output data tables O An output example using proc tabulate(from other project)

8 Possible Report Generation Methods O Excelxp in SAS O Pros O Amazing number of options and flexibility O Both of the data preparation and formatting processes could be finished in SAS O Cons O Date variables exported from SAS will be interpreted as a text variable O Why don’t we use ExcelXP? O We would like to have a set of Excel templates not only for this report, but for other requests. O Ideal: have SAS to do part of what VBA macro does

9 SAS DDE O What is DDE? O Inter-process communication between programs O Use one programming language to control/communicate with another O SAS DDE O Can export SAS data to Excel, Word O Two approaches O Execute all code directly in SAS O Create a pre-formed Excel template and populate it using SAS DDE (We use this one!)

10 DDE: Key steps O Write values in the specific row and column O To write ‘Overall’ in row 4 column 3-7 filename excel dde "excel| &excelin.!r4c3:r4c7" notab; data _null_; file excel; put "Overall"; run ; O Use existed macro to format cells: O To make the title in bold O In SAS data _null_; file cmdexcel; put '[select("R1C1:R1C' "&columns" '")]'; put '[RUN("PERSONAL.XLS!Macro4",FALSE)]'; O Macro4 in Excel Sub Macro4() Selection.Font.Bold = True End Sub

11 DDE: Key steps O Important system options options noxsync noxwait; noxwait: specifies that the command processor automatically returns to the SAS session after the specified command is executed noxsync: instructs SAS to continue processing as soon as the operating system command is issued O Open Excel O There are different ways of opening Excel by DDE O In this project, since we need to generate multiple workbooks, a SAS macro was used to open Excel. O Detail of the macro: Using Dynamic Data Exchange (DDE) and Macro Variables to Create Custom Excel Workbooks with Multi-Sheets O http://www2.sas.com/proceedings/forum2008/229-2008.pdf

12 DDE: Key steps O Save file filename cmds dde 'excel|system'; data _null_; file cmds; put '[SAVE.AS(“file directory")]'; put '[close]'; run; O More information on DDE: O SAS Professional Forum on LinkedIn O SAS Health User Group on LinkedIn

13 DDE: Demo O Object: O Generate a demographic summary report of the students in 3 different grades O Mean O Std Dev O Data: Data demo; Input grade ht wt; Cards; 1 155 72 1 146 64.2 2 140 44.3 2 148 56.2 3 159 70.4 3 152 68.2 … ;

14 DDE: Demo O Step: O 1. Create a template in Excel I saved this spreadsheet as demo.xlsx and named the template sheet summary O 2. Calculate mean and standard deviation in SAS proc sort data = demo; by grade; run; proc summary data=demo; var ht; class grade; output out=demo_summary; run;

15 DDE: Demo O Step: O 3. Call Excel template in SAS options noxwait noxsync; x '“file_directory\demo.xlsx"'; filename example1 dde 'excel|summary!r2c3:r4c3'; O 4. Write SAS output into Excel template data demo_summary; set demo_summary; file example1; if _stat_ = "MEAN" then put ht; run;

16 DDE: Demo O Step: O 5. Continue to write stand deviations to template filename example1 dde 'excel|summary!r5c3:r7c3'; data demo_summary; set demo_summary; file example1; if _stat_ = "STD" then put ht; run;

17 DDE: Demo O Step: O Save O Option1: close the opened excel file and click ‘Save’ when Microsoft asks you, and the file will be saved under the same directory as the template O Option2: Use SAS to close and save the file filename example1 dde 'excel|system'; data _null_; file example1; put '[SAVE.AS(“file_directory\file_name.xls")]'; put '[close]'; run;

18 DDE: Demo O Another options: O Use Excel VBA macro O Record the creation of the template as a macro and save it in Excel O The recorded macro for creating the template Sub tina_temp() Range("B1").Select ActiveCell.FormulaR1C1 = "Data Summary“ **Write ‘Data Summary’ to cell B1** Range("A2").Select ActiveCell.FormulaR1C1 = "Means“ **Write ‘Means’ A2** …. End Sub

19 DDE: Demo O Another option: O Use Excel VBA macro O Open a workbook in Excel options noxsync noxwait xmin; filename sas2xl dde 'excel|system'; data _null_; length fid rc start stop time 8; fid=fopen('sas2xl','s'); if (fid le 0) then do; rc=system('start excel'); start=datetime(); stop=start+10; do while (fid le 0); fid=fopen('sas2xl','s'); time=datetime(); if (time ge stop) then fid=1; end; rc=fclose(fid); run; O An Excel Window will open

20 DDE: Demo O Another option: O Use Excel VBA macro O Call the Excel macro template in SAS filename cmdexcel dde 'excel|system'; data _null_; file cmdexcel; put '[RUN("PERSONAL.XLS!tina_temp",FALSE)]'; run; O You will see the pop-up Excel be formatted like this:

21 DDE: Dem0 O Another option: O Use Excel VBA macro O Write output into Excel filename cmdexcel dde 'excel|Sheet1!r2c3:r4c3'; data demo_summary; set demo_summary; file cmdexcel; if _stat_ = "MEAN" then put ht; run; ** write mean values in** O After this step:

22 DDE: Demo O Another option: O Use Excel VBA macro O Why use Excel VBA? O VBA macros can be permanently stored in Excel. Therefore, they can be re-used for different purposes O User can create/record VBA macros, therefore, it’s a more flexible option.

23 Questions???

24 Reference O http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/defa ult/viewer.htm#win-sysop-xwait.htm O http://www.lexjansen.com/wuss/2007/ApplicationsDevelopment/APP_Smit hC_ImportingExcelFiles.pdf O http://www2.sas.com/proceedings/forum2008/229-2008.pdf O http://www.ats.ucla.edu/stat/sas/faq/sas2excel_dde.htm


Download ppt "Use SAS to Automate Hospital Reports generation Cardiac Service BC Stats Team, PHSA Tina Yang."

Similar presentations


Ads by Google