WINTER 2008
TECHIE TIPS
User Profile: Marje Fecht
Read.
Education Profile: Stephen Keelan
Read.
You can easily find out what's new in SAS 9.1 from new products to updates and enhancements.

Go to the SAS®9 link from our support.sas.com Web site.
For details on all of SAS' products and solutions, click here.
The SAScom blog: http://blogs.sas.com/sascom/
SAS Canada
ANOMALY DETECTION APPLICATION
By Bryan K. Beverly

BAE Systems Information Technology

The purpose of this application is to detect text strings associated with anomalies generated during the execution of a SAS job. This application is especially useful for searching for key words (such as ERROR, WARNING, FAILURE, etc.) in SASLOGS that have been written to external files. When one has several hundred lines of text in several hundred SASLOGS, this application will save time and energy, and is not susceptible to human error.

To use this application, one must supply the location of the text file and the term of interest. Using the UNIX “GREP” command, the application searches the location provided, lists the files that contains the term of interest, and sends the results in an e-mail message.

This application can also be used for searching for text strings in SAS programs. For example, if you wanted to know which programs in a specific directory contained SIGNON statements. So while this approach can work for any type of text string search, it is especially effective in searching for the anomalous needles in the haystacks of SASLOGS.

%macro detect(dir=,type=,keyword=);
options symbolgen;

/* CREATE A MACRO THAT COUNTS OBSERVATIONS */
%macro metadata (ds);
%global dset nvars nobs;
%let dset = &ds;
%let dsid = %sysfunc(open(&dset));
%let nobs = %sysfunc(attrn(&dsid,NOBS));
%let nvars = %sysfunc(attrn(&dsid,NVARS));
%let rc = %sysfunc(close(&dsid));
%mend metadata;

/* REFRESH A TEXT FILE THAT CAPTURES THE RESULTS FROM A GREP SEARCH */
x "cd /home/your_directory";
x "rm my.log";
x "cd &dir.&type";
x "grep &keyword * > /home/your_directory/my.log";

/* GIVE THE GREP COMMAND AT LEAST FIVE SECONDS TO EXECUTE */
data _null_;
snooze=sleep(5000);
run;

/* USE THE THE TEXT FILE AS INPUT FOR PROCESSING */
/* STORE THE RESULTS IN A MACRO VARIABLE */
filename test "/home/your_directory/my.log" lrecl=256;
data one;
infile test pad missover;
input @1 var1 $char256.;
call symput('text',var1);
run;

/* COUNT THE OBSERVATIONS */
%metadata(one);

/* IF ANOMALIES ARE DETECTED, THEN SEND THE RESULTS IN AN EMAIL MESSAGE */
%if &nobs>0 %then %do;
data _null_;
filename outbox email "SOMEBODY@EMAIL.NET" ;
file outbox
subject="ATTENTION!!!: Possible Processing Anomalies ( &keyword ) Dectected in &dir.&type !";
put "There was at least one file in &dir.&type where the string ( &keyword ) was found";
put " ";
put "&text";
run;
%end;

%mend detect;

/* EXECUTE THE APPLICATION FOR EACH TERM OF INTEREST */
%detect(dir=%str(/TOP_DIRECTORY),type=%str(/SUBDIRECTORY),keyword=%str(failure));
%detect(dir=%str(/TOP_DIRECTORY),type=%str(/SUBDIRECTORY),keyword=%str(ERROR:));
%detect(dir=%str(/TOP_DIRECTORY),type=%str(/SUBDIRECTORY),keyword=%str(stopped));

 
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. Copyright © 2007, SAS Institute Inc. All rights reserved.