Creating Dynamic Reports Using Data Exchange to Excel



Similar documents
Data Presentation. Paper Using SAS Macros to Create Automated Excel Reports Containing Tables, Charts and Graphs

Importing Excel File using Microsoft Access in SAS Ajay Gupta, PPD Inc, Morrisville, NC

SAS UNIX-Space Analyzer A handy tool for UNIX SAS Administrators Airaha Chelvakkanthan Manickam, Cognizant Technology Solutions, Teaneck, NJ

AN ANIMATED GUIDE: SENDING SAS FILE TO EXCEL

Managing very large EXCEL files using the XLS engine John H. Adams, Boehringer Ingelheim Pharmaceutical, Inc., Ridgefield, CT

Choosing the Best Method to Create an Excel Report Romain Miralles, Clinovo, Sunnyvale, CA

A Macro to Create Data Definition Documents

A Method for Cleaning Clinical Trial Analysis Data Sets

Search and Replace in SAS Data Sets thru GUI

ing Automated Notification of Errors in a Batch SAS Program Julie Kilburn, City of Hope, Duarte, CA Rebecca Ottesen, City of Hope, Duarte, CA

Combining SAS LIBNAME and VBA Macro to Import Excel file in an Intriguing, Efficient way Ajay Gupta, PPD Inc, Morrisville, NC

From The Little SAS Book, Fifth Edition. Full book available for purchase here.

We begin by defining a few user-supplied parameters, to make the code transferable between various projects.

Let SAS Modify Your Excel File Nelson Lee, Genentech, South San Francisco, CA

Health Services Research Utilizing Electronic Health Record Data: A Grad Student How-To Paper

Preparing your data for analysis using SAS. Landon Sego 24 April 2003 Department of Statistics UW-Madison

Importing Excel Files Into SAS Using DDE Curtis A. Smith, Defense Contract Audit Agency, La Mirada, CA

Managing Data Issues Identified During Programming

Paper RIV15 SAS Macros to Produce Publication-ready Tables from SAS Survey Procedures

How To Write A Clinical Trial In Sas

Create an Excel report using SAS : A comparison of the different techniques

Automated distribution of SAS results Jacques Pagé, Les Services Conseils HARDY, Quebec, Qc

Using Pharmacovigilance Reporting System to Generate Ad-hoc Reports

Methodologies for Converting Microsoft Excel Spreadsheets to SAS datasets

Web Reporting by Combining the Best of HTML and SAS

Using SAS to Control and Automate a Multi SAS Program Process. Patrick Halpin November 2008

Managing Tables in Microsoft SQL Server using SAS

ABSTRACT INTRODUCTION SAS AND EXCEL CAPABILITIES SAS AND EXCEL STRUCTURES

Using Microsoft Excel for Data Presentation Peter Godard and Cyndi Williamson, SRI International, Menlo Park, CA

From Database to your Desktop: How to almost completely automate reports in SAS, with the power of Proc SQL

Microsoft Office Word 2010: Level 1

THE HELLO WORLD PROJECT

Do It Yourself (DIY) Data: Creating a Searchable Data Set of Available Classrooms using SAS Enterprise BI Server

Instant Interactive SAS Log Window Analyzer

Better Safe than Sorry: A SAS Macro to Selectively Back Up Files

Counting the Ways to Count in SAS. Imelda C. Go, South Carolina Department of Education, Columbia, SC

Using SAS Enterprise Business Intelligence to Automate a Manual Process: A Case Study Erik S. Larsen, Independent Consultant, Charleston, SC

Tales from the Help Desk 3: More Solutions for Simple SAS Mistakes Bruce Gilsen, Federal Reserve Board

Integrating SAS and Excel: an Overview and Comparison of Three Methods for Using SAS to Create and Access Data in Excel

Using the Magical Keyword "INTO:" in PROC SQL

Customized Excel Output Using the Excel Libname Harry Droogendyk, Stratia Consulting Inc., Lynden, ON

EXTRACTING DATA FROM PDF FILES

PharmaSUG Paper AD11

EXST SAS Lab Lab #4: Data input and dataset modifications

Introduction to SAS Business Intelligence/Enterprise Guide Alex Dmitrienko, Ph.D., Eli Lilly and Company, Indianapolis, IN

White Paper. Thirsting for Insight? Quench It With 5 Data Management for Analytics Best Practices.

Using DDE and SAS/Macro for Automated Excel Report Consolidation and Generation

Writing Data with Excel Libname Engine

Effective Use of SQL in SAS Programming

ABSTRACT THE ISSUE AT HAND THE RECIPE FOR BUILDING THE SYSTEM THE TEAM REQUIREMENTS. Paper DM

Paper An Introduction to SAS PROC SQL Timothy J Harrington, Venturi Partners Consulting, Waukegan, Illinois

Utilizing Clinical SAS Report Templates with ODS Sunil Kumar Gupta, Gupta Programming, Simi Valley, CA

Innovative Techniques and Tools to Detect Data Quality Problems

Using FileMaker Pro with Microsoft Office

Develop highly interactive web charts with SAS

Top Ten Reasons to Use PROC SQL

CDW DATA QUALITY INITIATIVE

An macro: Exploring metadata EG and user credentials in Linux to automate notifications Jason Baucom, Ateb Inc.

Market Pricing Override

SAS ODS HTML + PROC Report = Fantastic Output Girish K. Narayandas, OptumInsight, Eden Prairie, MN

SUGI 29 Applications Development

REx: An Automated System for Extracting Clinical Trial Data from Oracle to SAS

You have got SASMAIL!

Applications Development

Automating SAS Macros: Run SAS Code when the Data is Available and a Target Date Reached.

Paper PO 015. Figure 1. PoweReward concept

Constructing a Table of Survey Data with Percent and Confidence Intervals in every Direction

Overview. NT Event Log. CHAPTER 8 Enhancements for SAS Users under Windows NT

Microsoft' Excel & Access Integration

Paper Merges and Joins Timothy J Harrington, Trilogy Consulting Corporation

Building a Marketing Dashboard using Excel and SAS. Tim Walters InfoTech Marketing

Statistics and Analysis. Quality Control: How to Analyze and Verify Financial Data

Automation of Large SAS Processes with and Text Message Notification Seva Kumar, JPMorgan Chase, Seattle, WA

Order from Chaos: Using the Power of SAS to Transform Audit Trail Data Yun Mai, Susan Myers, Nanthini Ganapathi, Vorapranee Wickelgren

One problem > Multiple solutions; various ways of removing duplicates from dataset using SAS Jaya Dhillon, Louisiana State University

Release 2.1 of SAS Add-In for Microsoft Office Bringing Microsoft PowerPoint into the Mix ABSTRACT INTRODUCTION Data Access

ABSTRACT INTRODUCTION CLINICAL PROJECT TRACKER OF SAS TASKS. Paper PH

Taming the PROC TRANSPOSE

Spelling Checker Utility in SAS using VBA Macro and SAS Functions Ajay Gupta, PPD, Morrisville, NC

Paper PO03. A Case of Online Data Processing and Statistical Analysis via SAS/IntrNet. Sijian Zhang University of Alabama at Birmingham

Unit 10: Microsoft Access Queries

Developing an On-Demand Web Report Platform Using Stored Processes and SAS Web Application Server

How To Use Sas With A Computer System Knowledge Management (Sas)

SPSS: Getting Started. For Windows

PharmaSUG Paper QT26

SAS Logic Coding Made Easy Revisit User-defined Function Songtao Jiang, Boston Scientific Corporation, Marlborough, MA

Parallel Data Preparation with the DS2 Programming Language

Using SAS With a SQL Server Database. M. Rita Thissen, Yan Chen Tang, Elizabeth Heath RTI International, RTP, NC

Transcription:

Creating Dynamic Reports Using Data Exchange to Excel Liping Huang Visiting Nurse Service of New York ABSTRACT The ability to generate flexible reports in Excel is in great demand. This paper illustrates an automated and easily managed process to calculate basic elements of a report, such as frequencies and means. The process also performs some basic statistical analysis to organize results and automatically generate a report based on a pre-designed Excel template. Introduction In today s health care industry, the ability to integrate comprehensive information and generate flexible reports is in great demand. An easily understandable and up to date report plays an important role in assisting health care professionals to improve quality of care and in supporting management to make better decisions. Generating reports involves organizing streamlined data, analyzing data, and presenting user-friendly results. In other words, it makes information useful in the real world. However, making the process to be more efficient and less labor intensive is a challenge for programmers and analysts. This paper uses a real world example to provide a detailed walkthrough of how to programmatically create and customize an Excel workbook containing SAS data. Background The example used for this paper is from a large urban health care agency. In order to provide higher quality services, the agency would like to have reports on patients and the agency administration on a regular basis. Providing up to date reports in a user-friendly format is a major responsibility of the programmers. Process Illustration Section I. Excel Template Preparation Because of the popularity and user-friendly interface of Excel, reports created by Excel are preferred by management. The first, and most important task, is to design and prepare a report template. More often, it is the most time-consuming stage. Programmers must not only have technical knowledge, they must also fully understand the purpose of a report. Enhanced communication skills will always help to achieve this goal. The example used in this paper contains multiple sheets with tables, charts and graphics. In addition, a sheet, named data, is used to receive analytical results from SAS. All results presented in the report are linked to the data sheet. Section II. Creating an Interactive Window Application The purpose of creating a user-friendly interactive window application is to allow anyone who executes program to have the flexibility to select criteria or a time frame without having to edit codes. Instead of using %let statement, the %WINDOW REPORT shown bellow will store user-defined criteria as global macro variables, which are used as conditional criteria while the program processes the rest of the procedures. %WINDOW REPORT IROW= 4 ICOLUMN= 5 ROWS= 25 COLUMNS= 75 COLOR=GRAY GROUP= hdrftr #2 @20 "Welcome to Outcome Repoting Systeme" COLOR=BLUE #20 @5 "Press [ENTER]" GROUP= criteria #5 @5 "Please enter the report beginning date(ddmonyyyy)" +3 begndate 9 ATTR=UNDERLINE AUTOSKIP=YES COLOR=RED #6 @5 "Please enter the report ending date(ddmonyyyy)" +3 enddate 9 ATTR=UNDERLINE AUTOSKIP=YES COLOR=RED #11 @5 "Please enter a specific region from the following: B, K, M, Q, S, N" / @5 region 40 ATTR=UNDERLINE color=red; %LET begndate = ; %LET enddate = ; %LET region = ; %MACRO REPORT; %DISPLAY report.hdrftr NOINPUT BLANK BELL ; %DISPLAY report.criteria ; %MEND REPORT; %REPORT; 1

After the parameter values are defined, a conditional statement is created from the following codes: call symput('cnt', put('if ' "borough" '=' quote("&region"), $20.)); %put cnt; As you can see from the log, if you entered B in the field of the region, the value of &cnt showed as: if borough = B. Section III. Creating data sets The macro variable &cnt is used to create two subsequent data sets for calculating frequencies and means, as well as to indicate whether a patient resides in a report region or in other regions. /*create two data sets for a reporting region and other regions*/ data pt_region pt_other; set report.datain; if "&begndate"d <=ddate <="&enddate"d; &cnt then output pt_region ; else output pt_other; /*create a data set with a regional indicator*/ data data_all; set report.datain; if "&begndate"d <=ddate <="&enddate"d; &cnt then report=1; else report=0; The data sets pt_region and pt_other are created for the purposes of calculating frequencies and means for a reporting region and other regions, respectively. The data set data_all is created for the purpose of performing statistical comparisons between a reporting region and other regions. Section IV. Calculating Frequencies and Means In the real world, information is usually presented as frequencies and means. The macros %DOFREQ and %DOMEAN meet this purpose. Based on the items put in separate %let statements: &varfreq and &varmean, they calculate frequencies and means and append results together for outputting. Also note that the macro %EXIST determines whether a data set exists while doing appending. It deletes an existing base data file if it is the first run of a loop. The following is the codes of macros %EXIST, %DOFREQ, AND %DOMEAN. /*the macro for deleting an existing file*/ %macro EXIST(dsn); %if %sysfunc(exist(&dsn)) %then %do; proc datasets library=work; delete &dsn; quit; %mend EXIST; /*the macro for calculating frequencies*/ %macro DOFREQ(count); proc freq data=&datain noprint ; tables &&new&n /list out=out&n; data out&n; length label $25.; set out&n; if &&new&n > 0 ; label="&&new&n"; %exist(freq); proc appenddata=out&n (rename=(&&new&n=value)) base=freq force; proc append data=out&n (rename=(&&new&n=value)) base=freq force; proc sort data=freq; %mend DOFREQ; /*the macro for calculating means*/ %macro DOMEAN(count); proc means data=&datain noprint ; var &&new&n; output out=out&n mean=mean; data mean&n; length label $15.; set out&n(drop=_type_); 2

label="&&new&n"; %exist(mean); proc append data=mean&n base=mean force; proc append data=mean&n base=mean force; proc sort data=mean; %mend DOMEAN; Section V. CHISQs and T-TESTs In order to help regional managers compare patients residing in one region with patients residing in other regions, CHISQ tests for all binary variables and T- TESTS for all continuous variables are performed. Although it is simple enough to obtain CHISQ results as a SAS data set through the features of the PROC FREQ, it is a little tricky to have the results from a t- test organized as a SAS data set. Version 8 SAS does not have the capability to create a SAS data set directly from the results of PROC TTEST. Nevertheless, the macro %DOTTEST adopts the features from SAS Output Delivery System (ODS) and examines the variances of a sample to determine a sample equality or inequality, and therefore to define a t-value and its probability. /*the macro running t-test for listed continuous variables*/ %macro DOTTEST(count); /*using ODS features to store results from t-test*/ ods output ttests=out1(keep=variable variances tvalue probt); ods output Equality=out2 (keep=variable fvalue probf); ods trace on; proc ttest data=&datain noprint; class report; var &&new&n; ods trace off; /*modify data sets from proc ttest and checking if a sample data is equal or not equal based on variances, and therefore to retain a proper t value and probability from a t-test*/ data out2(rename=(variable=label)); length variable $20.; merge out1 out2; by variable; if probf <=0.05 then do; if variances='unequal'; /*the sampel is not equal*/ end; else do; if variances='equal'; /*sample is equal*/ end; %exist(ttest); proc append data=out2 base=ttest force; proc append data=out2 base=ttest force; %mend DOTTEST; /*the macro for calculating chisq values for listed binary variables*/ %macro DOCHISQ(count); proc freq data=&datain noprint; tables report*&&new&n / chisq; output out=out (keep=p_pchi) chisq; data out; length label $20.; set out; label="&&new&n"; %exist(chisq); proc append data=out base=chisq force; proc append data=out 3

base=chisq force; proc sort data=chisq; %mend dochisq; Section VI. Running %DOFREQ, %DOMEAN, %DOCHISQ, and %DOTTEST The macro %INPUTVAR converts the variables listed from %put statements into macro variables and calls other macros %DOFREQ, %DOMEAN, %DOCHISQ, and %DOTTEST for generating a final output data set that includes the frequencies and means for a reporting region and other regions, as well as the statistical difference between them. The following codes shows how to put everything together to generate a final SAS data set. /*list variables for running frequencies or means*/ %let socfreq=agegroup1854 agegroup5564 agegroup6574 agegroup7584 agegroup85 white black hispanic asian otherrace female male nocharge duallyeligible medicareonly medicaidonly anyhmo privateinsurance otherpayment; %let varmean=los visit_ns; /*create data sets in order to convert listed variables to macro variables*/ data varfreq; input &socfreq; cards; data varmean; input &varmean; cards; %macro INPUTVAR(datain, varin, in); /*convert listed variables to macro variables*/ proc transpose data=&varin out=var2; proc sql noprint; select count(*) into :count from var2; quit; call symput('newcount', compress('new') compress(&count)); proc sql noprint; select _name_ into :new1 thru :&newcount from var2; quit; %let count=&count; /*assign observation numbers in order to merge*/ data var3(rename=(_name_=label)); set var2; obs=_n_; proc sort data=var3; /*run frequencies, means, chisq and t- values*/ %if &in=0 %then %do; %DOFREQ(&count); data freq(drop=value); merge var3 freq; proc sort data=freq; by obs; %if &in=1 %then %do; %DOMEAN(&count); data mean (rename=(_freq_=count mean=percent)); merge var3 mean; proc sort data=mean; by obs; %if &in=2 %then %do; %DOTTEST(&count); data ttest; merge var3 ttest; if probt <= 0.001 then sign='***'; else if 0.001 <= probt < 0.01 then sign= '**'; else if 0.01 <=probt < 0.05 then sign= '*'; 4

proc sort data=ttest; by obs; %if &in=3 %then %do; %DOCHISQ(&count); data chisq; merge var3 chisq; if p_pchi <= 0.001 then sign='***'; else if 0.001 < p_pchi < 0.01 then sign= '**'; else if 0.01 < p_pchi <= 0.05 then sign= '*'; proc sort data=chisq; by obs; %mend INPUTVAR; /*create an output data set for the reporting region*/ %INPUTVAR (pt_region, VARFREQ, 0); %INPUTVAR (pt_region, VARMEAN, 1); data region(rename=(count=c_region percent=p_region)); set freq mean ; /*create an output data set for the comparison*/ %INPUTVAR (pt_other, VARFREQ, 0); %INPUTVAR (pt_other, VARMEAN, 1); data other(rename=(count=c_other percent=p_other)); set freq mean ; /*examine statistical significance between the reporting region and the comparison*/ %inputvar (data_all, varmean, 2); %inputvar (data_all, varfreq, 3); /*combine outputs together*/ data output; merge region other; /*modify the data set for simplifying the output from the chisq and ttest results*/ data significant(keep=label sign); set chisq ttest; /*the final output data set*/ data finalout; merge output significant; by lable; Section VI. Loading Excel and output results into the template and save as a specific report After results are calculated and organized as a SAS data set, it is time to output. There are a few different ways to load Excel template. In the example, we use X command to activate the Excel template and write outputs into its data sheet. In addition, the codes below also write a regional title and a time frame into the data table, which will be dynamically reflected in a report title. /*loade an Excel template*/ options noxwait noxsync; x "c:\progra~1\micros~1\office\excel c:\reports\template.xls"; x = sleep(10); /*write a report title and the time frame into a data sheet*/ filename data1 dde "excel data!r1c1:r1c6" notab; file data1; title=compress("&region"); beg=compress(year("&beg"d)) '-' compress(month("&beg"d)); end=compress(year("&end"d)) '-' compress(month("&end"d)); put title $25. '09'x beg $10. '09'x end $10. '09'x; /*count the total observation from the final output data set in order to determine the number of rows needed to be filled in a data sheet of the template*/ 5

proc sql; select count(*) into :count from finalout; quit; Finally, the results are ready to be outputted. Using the most popular and powerful protocols for integrating SAS and Excel - Dynamic Data Exchange (DDE), this code will output the desired results to the template and save them as a particular regional report. /*output the final data set*/ filename data1 dde "excel data! r3c1:r%eval(&count+3)c5" notab; set finalout; file data1; if _n_ = 1 then put 'label' '09'x 'c_region' '09'x 'p_region' '09'x 'c_other' '09'x 'p_other' '09'x; put label $25. '09'x c_region 8. '09'x p_region 8.3 '09'x c_other 8. '09'x p_other 8.3 '09'x sign $8. '09'x ; Abdurazak, T. Using SAS Macros to Create Automated Excel Reports Containing Tables, Charts and Graphs. Proceedings of the twenty-seventh Annual SAS Users Group International Conference, paper 126, 2002. Mace, M. %Window: You Can Talk to the Users, and They Can Talk Back. Proceedings of the twenty-seventh Annual SAS Users Group International Conference, paper 192, 2002. Trademarks SAS is a registered trademark of SAS Institute Inc. in the USA and other countries. Indicates USA registration. Other brand name and product names are registered trademarks or trademarks of their respective companies. Contact Information Liping Huang Center for Home Care Policy and Research Visiting Nurse Service of NY 5 Penn Plaza, 11 th Floor New York, NY 10001 (212) 290 0520 E-mail: liping.huang@vnsny.org filename cmds dde 'excel system'; archive="c:\report_&boro" ".xls";; file cmds; put '[QUIT()]'; Conclusion This paper has shown an automated process of handling analytical results and outputting them to a pre-defined Excel template. It is easily modifiable for a variety of projects. Without having much knowledge of SAS, anyone who runs the program will be able to manipulate it with ease. References Vyverman, K. Using Dynamic Data Exchange to Export your SAS Data to MS Excel. Proceedings of the twenty-seventh Annual SAS Users Group International Conference, paper 5, 2002. 6