Event Viewer Application Log

Accessing the Application Log Using Windows 7

To open the Application Log:
  1. Open the Control Panel.
  2. Select System and security .
  3. Select Administrative tools.
  4. Double-click Event Viewer.
    Note: Select Continue if you receive a message stating that Windows needs your permission to continue.
  5. In the tree view, select Windows logs and then click on the left arrow to expand the window logs.
  6. Select Application log.
An alternate method of starting the Event Viewer is to enter eventvwr in the Search programs and files dialog box and click OK.

Viewing a SAS Event

If a SAS task ends abnormally, information about the task is placed in the Application Log. The Source column shows “SAS” as the event source. Messages from SAS/CONNECT display “SAS Job Spawner” as the event source. Double-clicking a SAS event opens the Event Properties window that contains information about the event.

Sending Messages to the Application Log Using a User-Written Function

Specifying the Function's First Parameter

SAS events can be sent to the Application Log by using a user-written function in either SAS code or SAS Component Language (SCL). Input to the function is a specific text string. This text string corresponds to the type of event and to the text string that appears in the Event Viewer:
yourfunction("type_of_event", "text_string");
The following table lists the types of events that are available for the first parameter.
Types of SAS Events
Type of Event
First Parameter Value
Error
“ERROR”
Warning
“WARNING”
Information
“INFORMATION”
Success Audit
“SUCCESSAUDIT”
Failure Audit
“FAILUREAUDIT”
Although the first parameter values that are displayed in the table are shown in uppercase, mixed case is also allowed. The second parameter of the function is a string that appears in the Windows Event Viewer.

Examples of Using the User-Written Function to Write to the Event Log

In the following example, the existence of a semaphore file is checked before SAS performs lengthy processing:
%macro pdata(file);
    %let cmdstr = "dir &file";
    options noxwait;
    data _null_;
       call system(&cmdstr);
    run;
    %put &sysrc = sysrc;
    %put &file;
    %if &sysrc=0 %then %do;
       filename indata "&file";
       /* Your data step code for this file.  */
       DATA a;
          infile indata length=linelen;
          length line $ 200;
          input @1 line $ varying200. linelen;
       PROC print;
       run;
    %end;
    %else %do;
       /*  Log an Event of type Error.  */
       %let cmdstr = %str("The file &file did not exist 
                              so no data step ran.");
       %put &cmdstr;
       DATA _null_;
          x=ntlog("INFORMATION",&cmdstr);
       run;
    %end;
 %mend;

 %pdata(c:\config.syss) 
The following is SCL code to write to the Application Log:
/* Build a frame and add a pushbutton.  Change the Attribute 
Name “name” to “object1”.  In the Source window, add the 
following code. */
object1:

x=ntlog("INFORMATION", "This is an INFORMATION event.");
x=ntlog("WARNING", "This is a WARNING event.");
x=ntlog("ERROR", "This is an ERROR event.");
x=ntlog("SUCCESSAUDIT", "This is a SUCCESSAUDIT event.");
x=ntlog("FAILUREAUDIT", "This is a FAILUREAUDIT event.");

return;

Sending Messages to the Application Log Using LOGEVENT.EXE

Using the Windows LOGEVENT.EXE utility that is provided by the Windows Resource Kit, you can send your own information messages to the Application Log from within SAS code.
In the following example, the existence of a semaphore file is checked before SAS performs some lengthy processing.
%macro pdata(file);
   %local cmdstr;
   %let cmdstr = "dir &file";
   options noxwait;
   DATA _null_;
      call system(&cmdstr);
   run;
   %if &sysrc=0 %then %do;
      filename indata "&file";
      /* Your data step code for this file.  */
      DATA a;
         infile indata length=linelen;
         length line $ 200;
         input @1 line $ varying200. linelen;
      PROC print;
      run;
   %end;
   %else %do;
      /*  Log an Event of type Error.  */
      %let cmdstr = %bquote(c:\support\sasset2\logevent.exe -s E 
      "The file &file did not exist so no data step ran.");
      DATA _null_;
         %sysexec &cmdstr;
      run;
   %end;
%mend;

%pdata(c:\config.syss)
When you double-click the event in the Application Log, the Event Properties window displays the message in the Description box.
For information about LOGEVENT.EXE, see the documentation for the Windows Resource Kit.