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



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

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

Simulate PRELOADFMT Option in PROC FREQ Ajay Gupta, PPD, Morrisville, NC

Applications Development

Enhancing the SAS Enhanced Editor with Toolbar Customizations Lynn Mullins, PPD, Cincinnati, Ohio

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

Combining External PDF Files by Integrating SAS and Adobe Acrobat Brandon Welch, Rho, Inc., Chapel Hill, NC Ryan Burns, Rho, Inc.

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

A Microsoft Access Based System, Using SAS as a Background Number Cruncher David Kiasi, Applications Alternatives, Upper Marlboro, MD

Generating Microsoft Word Macros that Automate the Organization and Maintenance of SAS Tables, Listings and Figures

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

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

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

EXTRACTING DATA FROM PDF FILES

Hummingbird Enterprise

It s not the Yellow Brick Road but the SAS PC FILES SERVER will take you Down the LIBNAME PATH= to Using the 64-Bit Excel Workbooks.

Using SAS DDE to Control Excel

ABSTRACT INTRODUCTION SAS AND EXCEL CAPABILITIES SAS AND EXCEL STRUCTURES

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

How To Write A Clinical Trial In Sas

THE HELLO WORLD PROJECT

Creating Dynamic Reports Using Data Exchange to Excel

Automatic Conversion of SAS Enhanced Programs to PDF

Mail Merge Creating Mailing Labels 3/23/2011

A Recursive SAS Macro to Automate Importing Multiple Excel Worksheets into SAS Data Sets

PharmaSUG 2014 Paper CC23. Need to Review or Deliver Outputs on a Rolling Basis? Just Apply the Filter! Tom Santopoli, Accenture, Berwyn, PA

Paper Creating SAS Datasets from Varied Sources Mansi Singh and Sofia Shamas, MaxisIT Inc, NJ

Preserving Line Breaks When Exporting to Excel Nelson Lee, Genentech, South San Francisco, CA

Need for Speed in Large Datasets The Trio of SAS INDICES, PROC SQL and WHERE CLAUSE is the Answer, continued

AN ANIMATED GUIDE: SENDING SAS FILE TO EXCEL

Flat Pack Data: Converting and ZIPping SAS Data for Delivery

Methodologies for Converting Microsoft Excel Spreadsheets to SAS datasets

While You Were Sleeping - Scheduling SAS Jobs to Run Automatically Faron Kincheloe, Baylor University, Waco, TX

9.1 SAS/ACCESS. Interface to SAP BW. User s Guide

Programming in Access VBA

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

Using The SAS System and Dynamic Data Exchange to Populate Microsoft Word Documents with Text, Tables, and Graphs

You have got SASMAIL!

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

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

PROC SUMMARY Options Beyond the Basics Susmita Pattnaik, PPD Inc, Morrisville, NC

Switching from PC SAS to SAS Enterprise Guide Zhengxin (Cindy) Yang, inventiv Health Clinical, Princeton, NJ

Essential Project Management Reports in Clinical Development Nalin Tikoo, BioMarin Pharmaceutical Inc., Novato, CA

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

Abstract. Introduction. System Requirement. GUI Design. Paper AD

Paper FF-014. Tips for Moving to SAS Enterprise Guide on Unix Patricia Hettinger, Consultant, Oak Brook, IL

VBA Microsoft Access 2007 Macros to Import Formats and Labels to SAS

A Quick Guide to the WinZip Command Line Add-On

ABSTRACT INTRODUCTION

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

SAS Office Analytics: An Application In Practice

Technical Paper. Defining an ODBC Library in SAS 9.2 Management Console Using Microsoft Windows NT Authentication

A Closer Look at PROC SQL s FEEDBACK Option Kenneth W. Borowiak, PPD, Inc., Morrisville, NC

A Macro to Create Data Definition Documents

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

Migrating to Excel 2010 from Excel Excel - Microsoft Office 1 of 1

Overview of sharing and collaborating on Excel data

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

Getting Started CHAPTER 1

Writing Data with Excel Libname Engine

PharmaSUG Paper QT26

Using Macros to Automate SAS Processing Kari Richardson, SAS Institute, Cary, NC Eric Rossland, SAS Institute, Dallas, TX

Microsoft Migrating to Word 2010 from Word 2003

Excel & Visual Basic for Applications (VBA)

PharmaSUG Paper AD03

While You Were Sleeping - Scheduling SAS Jobs to Run Automatically Faron Kincheloe, Baylor University, Waco, TX

STEP 2: UNIX FILESYSTEMS AND SECURITY

Job Streaming User Guide

ABSTRACT INTRODUCTION CLINICAL PROJECT TRACKER OF SAS TASKS. Paper PH

Session Attribution in SAS Web Analytics

Word 2010: Mail Merge to with Attachments

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

Technical Paper. Migrating a SAS Deployment to Microsoft Windows x64

Download and Installation Instructions. Visual C# 2010 Help Library

PharmaSUG Paper AD11

Wimba Create. Version 2.6. Installation Guide

Macros in Word & Excel

Working with Macros and VBA in Excel 2007

OVERVIEW OF THE ENTERPRISE GUIDE INTERFACE

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel.

Autodesk Product Manager Tool

PUT, DBLOAD AND ODE: Three Ways to Export Data to Excel and Why To Use Them

Microsoft Office Live Meeting Events User s Guide

Migrating from SAS 9.3 to SAS 9.4: SAS communicating with MS Office Products

Importing and Exporting With SPSS for Windows 17 TUT 117

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

Excel with SAS and Microsoft Excel

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

Checking Spelling and Grammar

SUGI 29 Data Warehousing, Management and Quality

Quick Reference Guide

OneTouch 4.0 with OmniPage OCR Features. Mini Guide

Converting Winisis Database into Access or Excel Database

Transcription:

PharmaSUG 2015 - Paper P017 Spelling Checker Utility in SAS using VBA Macro and SAS Functions Ajay Gupta, PPD, Morrisville, NC ABSTRACT In Pharmaceuticals/CRO industries, it is quite common to have typographical error during the data entry, data set programming, and table programming. This typographical error if not catch on time can add more programming/reviewer time and can affect the quality of deliverables. In order to find the misspelled words in SAS data set and tables, programmer normally review the data visually which can be tedious and prone to error. This paper will introduce a method to report all the misspelled word from table, listings, and SAS data set to a Word document in SAS using word basic commands via DDE (Dynamic Data Exchange) and SAS functions. If needed, this macro will be extended to find misspelled word from other file format for e.g. Microsoft Excel. INTRODUCTION In Pharmaceutical/CRO industries, it is quite common to have typographical error during the data entry, data set programming, and table programming. This typographical error if not caught on time can add more programming/reviewer time and can affect the quality of deliverables. In order to find the misspelled words in the SAS data set and tables, programmers normally review the data visually which can be tedious and prone to error. So, in order to expedite the review process and save programming time, it would be helpful if the programmer could create a document containing the list of misspelled words from all the tables and listings. Also, it will be helpful if we can identify misspelled words from the SAS dataset and other file format for e.g. EXCEL. This can cut down the data management and programming time and allow them to concentrate more on major issues other than typographical errors in the data. This paper will introduce a method to get the misspelled word(s) from the Word/rtf document in SAS using word basic commands and VBA macros via DDE (Dynamic Data Exchange). This solution can be further updated to get misspelled word(s) from SAS dataset or other file format for e.g. EXCEL. This paper introduces a macro which will highlight misspelled word(s) and create a list of all misspelled word(s) in separate document. The entire process involves SAS, Word, and VBA macro which is automated by a SAS macro called %SPELLCHECK. TECHNIQUE & MECHANISM The program is divided into two parts first part will describe the process of finding the misspelled word(s) from.rtf or word document and second part will describe the process of finding the misspelled word(s) from the SAS data set or other file formats for e.g. Excel,.CSV. The general process of finding the misspelled word from rtf or word document is as follows: 1. Open each file in Word. 2. Execute the VBA macro Spellcheck. 3. SAS processing to get the list of misspelled word. 4. Save final documents and close. The general process of finding the misspelled word from SAS data set or other file format for e.g. Excel is as follows: 1. Import the Excel file in SAS (applies to other file format!) and create a SAS data set. This step is only applicable if the file format is other than SAS data set. 2. Create listings from SAS data set in.rtf format. 3. Open each file in Word. 4. Execute the VBA macro Spellcheck. 5. SAS processing to get the list of misspelled word. 6. Save final documents and close. To automate these steps, the DDE solution is leveraged to build the communication bridge between SAS and Word 2003. WordBasic commands (Microsoft Corporation, 1999) can be sent from SAS via DDE to enable SAS to take control of Word 2003. RECORD VBA MACRO IN WORD TO CHECK SPELLING For many, perhaps most SAS developers the easiest and fastest way to write VBA code is to first go into a Microsoft application (in this paper Microsoft Word is used as the application), turn on the macro recorder, perform the steps 1

and functions desired, and then terminate the macro recorder. The end result is a stored VBA program (macro) that can be executed at a later date. This makes it possible for a SAS developer to automate tasks in the Microsoft application, and therefore vastly improve the functionality of an integrated system that takes advantage of the relative strengths of the SAS System and the Microsoft application. Steps to record VBA Macro are as follows: 1. Open Word. 2. Click ALT+F11. 3. Paste the SPELLCHECK VBA macro. 4. Select Ok. 5. Select Ok. 6. Close the document. VBA MACRO: SPELLCHECK Please see below VBA code for SPELLCHECK MACRO which will perform the following tasks: Run spell check on the active document. Highlight all the spelling errors and later save this document as Misspelled_Highlight.rtf on default location for e.g. My Documents. Create a separate word document and list all the misspelled word and save the document as Misspelled_Highlight.rtf in the default location ( e.g. My Documents ). Sub SPELLCHECK () End Sub 'Define and set initials parameters. Dim doctarget As Document Dim docreport As Document Dim rng As Range Set doctarget = ActiveDocument Set docreport = Documents.Add 'Highlight all misspelled words. For Each rng In doctarget.spellingerrors rng.font.bold = True rng.font.underline = True rng.font.size = 20 rng.font.italic = True rng.highlightcolorindex = wdyellow 'Copy all misspelled words into new document. Next 'Save Report. docreport.range.insertafter rng.text & vbnewline docreport.saveas FileName:=" Misspelled_List.rtf", _ 'Save Target file. FileFormat:=wdFormatRTF doctarget.saveas FileName:=" Misspelled_Highlight.rtf", _ FileFormat:=wdFormatRTF 2

OPEN THE TARGET FILE IN WORD AND EXECUTE THE SPELLCHECK VBA MACRO Prior to executing these statements, there are two system options needed NOXWAIT and NOXSYNC. The NOXWAIT option specifies that the DOS command prompt window disappears without one having to type EXIT when the process is finished, while the NOXSYNC specifies that the process should execute asynchronously. That is, control is returned immediately to the SAS System and the command continues executing without interfering with your SAS session. In order for a client/server communication link to be established, both SAS and Word must be running. Therefore, for the first iteration, it is necessary to programmatically launch Word from a SAS session. There are several techniques available to launch Word from SAS. The simplest one is the following statement: %LET RC=%SYSFUNC(SYSTEM(START WINWORD)); The above command is dependent on the completion of the previous command. Therefore, the SLEEP function can be used frequently in the SAS command/data step that is dependent on the previous job finishing. These will avoid the error that occurs due to the delay in the execution of previous SAS command or DATA step. An example of the SLEEP function is given below, where the system sleeps for 5 seconds X=SLEEP(5); The above step will pause SAS session for five seconds. To communicate with Word from SAS, the following FILENAME statement is used to establish the linkage between SAS and Word via the DDE triplet: FILENAME word DDE 'WINWORD SYSTEM'; Now, the following data step will execute the SPELLCHECK macro and create reports. This data step will initially clear all error start up errors and open the target file. Later, it will execute the SPELLCHECK macro and close the word session. FILE word; /*Below command will clear all initial error at the start up*/ PUT '[On Error Resume Next]'; /*below command will open the target document*/ PUT '[FILEOPEN.Name = "' "&in" '"]'; /*Below command will execute the SPELLCHECK VBA code*/ PUT '[SPELLCHECK()]'; /*Below command will close word document*/ PUT '[FILECLOSE]'; /*Below command will exit from word*/ PUT '[FILEEXIT]'; &in is the macro variable containing the name and location of target file. Due to technical limitations of spell checker function (word not present in dictionary) in word, there is a possibility that the SPELLCHECKER VBA macro might not be able to find all misspelled word. The best solution here is to add custom dictionary in word and use it as a first preference. Also, PROC SPELL (Okerson Barbara, 2007.) procedure can be added in this SAS macro to make it more powerful. CREATE WORD FILE FROM SAS DATA SET OR OTHER FILE FORMAT In order to find the misspelled word from SAS dataset or other file format for e.g. EXCEL. Please see instructions below. In case, the file format is EXCEL then covert excel to SAS dataset by using the LIBNAME Statement. If the SAS\ACCESS license is available, the following libname can be used: LIBNAME xls excel "&location\raw_1.xls" HEADER=no MIXED=yes; LIBNAME dat "&location"; DATA dat.&out.; SET test. $Sheet1 n (firstobs=2); 3

In the above DATA step, &location is the production location and &out is the output dataset created and saved in library dat. Further, convert the SAS dataset into RTF document using the code below: ods rtf file="c:\temp.rtf" style=journal; PROC PRINT DATA=test LABEL; ods rtf close; After creating the RTF document from SAS data set or other file format for e.g. EXCEL user can execute the SPELLCHECK VBA Macro to get the misspelled word. %SPELLCHECK To facilitate and automate the above discussed steps a SAS macro called %SPELLCHECK was developed for SAS v9.2 or above (see Appendix for details). The user can easily extend the macro to fit other SAS versions. There is only one keyword parameter: In: Define the path and the name of the input Word file, e.g., C:Target.rtf. Below is the simple macro call to %SPELLCHECK. % SPELLCHECK(in= Target.rtf); Below is the example showing list of misspelled word in Misspelled_List.rtf. Output 1. List of all misspelled word in Misspelled_List.rtf Below is the example showing highlighted misspelled word in Misspelled_Highlight.rtf. 4

Output 2. Highlighted misspelled word in Misspelled_Highlight.rtf CONCLUSION Above solution demonstrates an innovative approach to find spelling errors without any formatting changes in the document. This solution requires minimal amount of coding and can be further modified to take advantage of other Word functions. REFERENCES Gupta Ajay, 2012. Watermarking and Combining Multiple RTF Outputs in SAS. Proceedings of the PharmaSUG 2012 Conference, paper CC06. Gupta Ajay, 2013. Combining First Page of Multiple RTF Outputs in SAS using Bookmark and VBA Macro. Proceedings of the PharmaSUG 2013 Conference, paper CC24. Okerson Barbara, 2007. Old But Not Obsolete: Undocumented SAS Procedures. Proceedings of the SESUG 2007 Conference, paper SD06. http://www.sascommunity.org/wiki/proc_spell http://msdn.microsoft.com http://www.techrepublic.com/ 5

ACKNOWLEDGMENTS Thanks to Lindsay Dean, Daniela Popa, Ken Borowiak, David Gray, Richard DAmato, Lynn Clipstone, Thomas Fritchey, and PPD Management for their reviews and comments. Thanks to my family for their support. DISCLAIMER The content of this paper are the works of the authors and do not necessarily represent the opinions, recommendations, or practices of PPD. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Name: Ajay Gupta, M.S. Enterprise: PPD Inc. Address: 3900 Paramount Parkway City, State ZIP: Morrisville, NC-27560 Work Phone: (919)-456-6461 Fax: (919)-654-9990 E-mail: Ajay.Gupta@ppdi.com, Ajaykailasgupta@aol.com SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product names are trademarks of their respective companies. 6

APPENDIX: %MACRO SPELLCHECK(IN=); /*INITIATE OPTIONS*/ OPTIONS NOXWAIT NOXSYNC; %LET IN=&IN.; /*START WORD*/ %LET RC=%SYSFUNC(SYSTEM(START WINWORD)); /*EXECUTE SPELL CHECK MACRO*/ FILENAME word DDE 'WINWORD SYSTEM'; FILE word; /*BELOW COMMAND WILL CLEAR ALL INITIAL ERROR AT THE START UP*/ PUT '[ON ERROR RESUME NEXT]'; /*BELOW COMMAND WILL OPEN THE TARGET DOCUMENT*/ PUT '[FILEOPEN.NAME = "' "&IN" '"]'; /*BELOW COMMAND WILL EXECUTE THE SPELLCHECK VBA CODE*/ PUT '[SPELLCHECK()]'; /*BELOW COMMAND WILL CLOSE WORD SESSION*/ PUT '[FILECLOSE]'; PUT '[FILEEXIT]'; %MEND SPELLCHECK; 7