[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Log file reading program
From:       "Terjeson, Mark" <TERJEM () DSHS ! WA ! GOV>
Date:       2004-11-30 19:18:17
[Download RAW message or body]

Hi David,

There are occasions where certain error messages
cannot be eliminated for various reasons during
execution.  For these cases a small database
(i.e. a dataset) can contain text to ignore.
I send this along just for you to have fun with.
Please find code below.  Maybe an idea or two
will feed your new project....



Hope this is helpful,
Mark Terjeson
Reporting, Analysis, and Procurement Section
Office of Medicaid Systems & Data
Division of Audit & Information Systems
Department of Social and Health Services
State of Washington
mailto:terjem@dshs.wa.gov






*******************************************************;
*                                                     *
* Program: CheckLog.sas (version 2)                   *
*                                                     *
* Purpose: Load macros that upon request will report  *
*          whether or not any ERROR or WARNING lines  *
*          exist in the current SAS log window.  The  *
*          benefit is eliminate those rare occasions  *
*          that you have assumed that the log has no  *
*          errors in it and it really does!           *
*                                                     *
* Written: 07/31/98 - Mark Terjeson                   *
*                                                     *
* Modified:09/22/00 - add table of lines to ignore.   *
*                                                     *
* Note:    Any SAS OPTIONS settings used within this  *
*          program is transparent to the user, since  *
*          it saves off and replaces previous values  *
*                                                     *
* Note:    To invoke: place  %checklog()  at the end  *
*          of your program.  If it is the last thing  *
*          in your code then results will be visible  *
*          at the end of your log where they will be  *
*          more readily noticed.                      *
*                                                     *
* Call:      %CheckLog;                               *
*                                                     *
*                                                     *
* <optional>                                          *
* Call:      %CheckLog(Expected=<dsn>,                *
*                      ExpMsg=<varname>)              *
*                                                     *
* Parameters:  Expected - name of dataset with a      *
*              character variable containing the      *
*              text of messages to ignore.            *
*              The default is null - all messages     *
*              will be reported.                      *
*                                                     *
*              ExpMsg - the name of the variable in   *
*              the Expected dataset.  The default is  *
*              ExpMsg.  This value is ignored if      *
*              Expected is not passed as well.        *
*                                                     *
*              Only the beginning of the warning/error*
*              text needs to match a value to be ig-  *
*              nored.  For example, "ERROR 1" in      *
*              the dataset would cause                *
*                ERROR 1-123 ....                     *
*                ERROR 123-5 ....  to both be ignored *
*                                                     *
*******************************************************;


%macro HoldOpt(OptName=,       /* Option to check and hold value   */
               OptValue=XX);   /* Macro var name to hold value     */

    %if &OptValue eq XX %then %let OptValue = Hold&OptName;
    %global &OptValue;

    %let &OptValue = %sysfunc(getoption(&OptName));
%mend;


   * drop expected errors ;
%macro DropExp(Token=,
               Expected=,
               ExpVar=);

    proc sql;
        create table _&Token as
        select
                 e.*,
                 sum(case
                         when upcase(_pline) like upcase(trim(&ExpVar)||'%')
                         then 1
                         else 0
                     end) as DropIt
        from
                 _&Token e,
                 &Expected x
        group by
                 _&Token,_pline
        having
                 DropIt eq 0
        ;
    quit;

    options notes;
    %if &SQLobs ne &&_&Token %then
      %do;
        %put ;
        %put NOTE: Reporting of some expected %upcase(&token)(s) was
suppressed.;
      %end;
    %let _&Token = &sqlobs;
    options nonotes;
%mend;


    * create the visual report ;
%macro _shwlog(_token);
    %let _token=%upcase(&_token);

    data _null_;
        if compress("&&_&_token") not in('0','.') then
            do;
                set _&_token end=_done;
                if _N_ eq 1 then put / "&_token.:"
                    %eval(48-%length(&_token))*'_'
                    "These &_token.(s) were found in log above.";
                substr(_pline,%eval(%length(&_token)+1),1) = ':';
                put _pline;
                if _done eq 1 then put "&_token.:"
                    %eval(48-%length(&_token))*'_'
                    "These &_token.(s) were found in log above.";
            end;
        else
            do;
                put / 49*'_' "No &_token.(s) were found in log.";
            end;
    run;
%mend;


    * re-display error/warning messages at end of log ;
%macro checklog(Expected=,
                ExpVar=ExpMsg);

    %HoldOpt(OptName=Notes,OptValue=HoldNts);
    %HoldOpt(OptName=source,OptValue=HoldSrc);
    %HoldOpt(OptName=obs);

    options nonotes nosource obs=max;

    %let FN = c:\SL%sysfunc(time(),5.).tmp;
    filename _saslog "&FN";
    %let rc=%sysfunc(fdelete(_saslog));

    %if %substr(&sysver,1,1) eq 6 %then
        %str(dm log "file &FN";);
    %else
        %str(dm log "file &FN" log;);

    %if %sysfunc(fexist(_saslog)) eq 0 %then
        %do;
            options notes;
            %put NOTE: The log was empty;
            %goto Quit;
        %end;

    data _error(keep=_error _pline)
         _warning(keep=_warning _pline);

        length _pline $ 200;

        infile _saslog length=_lenvar end=_done;
        input @1 _pline $varying. _lenvar;
        if _pline eq :'ERROR' then
            do;
                _error+1;
                output _error;
            end;
        if _pline eq :'WARNING' then
            do;
                _warning+1;
                output _warning;
            end;
        if _done then
          do;
              call symput("_error",compress(_error));
              call symput("_warning",compress(_warning));
          end;
    run;

    %* If the Expected file does not exist, put a note ;
    %* in the log and then reset the variable to null. ;

    %if %sysfunc(exist(&Expected)) eq 0 %then
      %do;
        options notes;
        %put ;
        %put NOTE: Data set (&Expected) containing expected messages does
not exist;
        %put ;
        %let Expected = ;
        options nonotes;
      %end;

    %if &Expected ne %then
        %DropExp(token=warning,expected=&Expected,expvar=&expvar);
    %_shwlog(warning);
    %if &Expected ne %then
        %DropExp(token=error,expected=&Expected,expvar=&expvar);
    %_shwlog(error);

    proc delete data=_error _warning;
    run;

    %let rc=%sysfunc(fdelete(_saslog));
    filename _saslog clear;

  %Quit:
    options &HoldNts &HoldSrc obs=&HoldObs;
%mend;


*******************************************************;
*                    End Of Module                    *
*******************************************************;



































-----Original Message-----
From: David Fickbohm [mailto:DavidF@HOMEGAIN.COM]
Sent: Tuesday, November 30, 2004 9:57 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Log file reading program

People,
I have created a simple sas program that reads the log file.  Currently it
looks for "error", "warning", and, "copyright".   If it finds "error" or
"warning" it sends a email to me saying things did not go correctly.  If it
does not find "error" or "warning" it send an email to me saying "successful
run" and the jobname.

What else would you suggest I add to the program.  I would also like to add
the ability to show the date and time the job ran.

Thoughts on these two questions would be appreciated.

Thanks
Dave

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic