NESUG 2009 Coders' Corner

A Utility Program for Quickly Identifying LOG Error or Warning Messages Zhengyi Fang and Paul Gorrell Social & Scientific Systems, Inc., Silver Spring, MD

ABSTRACT This paper will show you how to create and install a utility program that will allow Windows users to SAS® error or warning messages quickly and easily by right-clicking the LOG file in Windows Explorer. All and only LOG lines containing ‘error’, ‘warning’, ‘uninitialized’, or other specified strings will be displayed in a DOS prompt. A one-line batch file is all that needs to be created. Installation of this utility program is very simple. In fact, it’s as simple as adding a new item to the right-click menu in Windows Explorer for the SAS LOG file. Each step in creating and using this file will be demonstrated.

INTRODUCTION After a programmer runs a batch SAS program, the first thing the programmer should do is to check the LOG file to see if the LOG file has any error, warning, or other relevant notes such as ‘NOTE: MERGE statement has than one data set with repeats of BY values’. It can be consuming to search for separate messages containing errors, warnings, and other notes of concern. This paper will show you a very simple CHECK LOG utility program that allows Windows users to find SAS error, warning messages, or unusual notes quickly and easily by right-clicking the LOG file in Windows Explorer.

CREATION OF A BATCH FILE Batch files are simple text files containing one or more lines with commands that are executed in sequence. Any filename can be used, but the file extension has to be BAT. For example, you may save it as CHECKLOG.BAT.

The following one-line batch file is all that is needed for a batch file that will search for specified alphanumeric strings. We will explain each command and the DOS syntax.

cmd /k findstr /i "string1 string2….stringn" %1

Detailed explanation of the code is as follows:

cmd Microsoft DOS command which starts a new instance of Windows command interpreter.

/k command which executes the specified command and continues to run next command.

findstr command to search for specified strings in files.

/i command to instruct to ignore the case of characters when searching for the string

%1 DOS batch parameter. %1 means the file that you want to perform the search.

Below is a batch file we currently use. The specified strings to search for are listed inside the quotation mark.

cmd /k findstr /i "uninitialized error warning repeats performing overwritten" %1

Table 1 - A List of Search Strings and Example LOG Messages Search String Example SAS LOG Message uninitialized Variable XXXX is uninitialized error ERROR: variable ID has been defined as both character and numeric warning WARNING: The data set WORK.COMB2 may be incomplete. repeats MERGE statement has more than one data set with repeats of BY values Missing values were generated as a result of performing an operation on missing performing values overwritten The variable XXXX on data set DATA1 will be overwritten by data set DATA2

1 NESUG 2009 Coders' Corner

Specific LOG message may be dependent on system options. For example, the last message in the table is generated when the SAS option MSGLEVEL=I is used. This option tells SAS to additional notes pertaining to index usage, merge processing, and sort utilities along with standard notes, warnings, and error messages.

INSTALLATION OF THE UTILITY The installation can be completed by adding a new item to the right-click menu in Windows Explorer for the SAS LOG file.

1) Open Windows Explorer

2) Select Tools

3) Select Folder Options (see screen shot below)

4) Select File Types

5) Select LOG under Extensions (see screen shot below)

2 NESUG 2009 Coders' Corner

6) Select Advanced (see screen shot below)

7) Select New (see screen shot below)

8) Type Check LOG (or other name you want to use) in the “Action” text box. In the text box for "Application used to perform action", browse to and select the BAT file (see a screen shot below).

9) Click OK

10) Click Close

3 NESUG 2009 Coders' Corner

HOW TO USE THE UTILITY In Windows Explorer, right-click the LOG file you want to check, then select and click Check LOG (or other name you put in the action window in step 8) in the menu. See a screen shot below. A DOS screen (see below) will be pop- up. Any error, warning, or other messages containing strings you specified will be displayed in the DOS prompt.

DISCUSSION This paper illustrates a simple and easy way to check SAS LOG files. There are numerous ways in which this utility can be enhanced or tailored to your specific needs. We hope that you can enhance or modify this utility to meet your needs.

Below are three example expansions of this utility:

1) LOG lines found in the DOS screen could be output to a file for documentation. See sample code below. If you want to concatenate the LOG lines to an existing file, you should > with >>.

cmd /k findstr /i "uninitialized error warning repeats performing overwritten" %1 >c:\sas_utility\error_lines.doc

4 NESUG 2009 Coders' Corner

2) The following commands may be useful.

/c: allows you to check for an exact combination of words. See sample code below.

cmd /k findstr /i /c:"MERGE statement has more than one data set with repeats of BY values" /i /c:"Character values have been converted" /i /c:“error” /i /c:”warning” %1

/n prints the line number. This would be helpful for locating errors. See sample code below.

cmd /k findstr /i /n "uninitialized error warning repeats overwritten" %1

3) Multiple CHECK LOG utilities with different level of messages are allowed to create, i.e., multiple CHECK LOG items can be added to the right-click menu.

Details on syntax and commands can be found in the references.

REFERENCES 1. Computer Hope.COM – a website for free online computer support and computer related information http://www.computerhope.com

2. XP Professional Product Documentation http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/findstr.mspx?mfr=true

ACKNOWLEDGEMENTS The authors would like to thank Shiquan Hu, Kathy McMillan, Valerie Aschenbach, and Lita Manuel of Social & Scientific Systems, Inc., for their helpful comments.

CONTACT INFORMATION Zhengyi Fang and Paul Gorrell Social & Scientific Systems, Inc. Silver Spring, MD 20910 Email: [email protected] and [email protected] Web: www.s-3.com

TRADEMARKS 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 a USA registration.

Other brand and product names are registered trademarks or trademarks of their respective companies.

5