Previous Page | Next Page

Using Windows System Tools with SAS under Windows

Event Viewer Application Log


Accessing the Application Log Using Windows Vista

To open the Application Log:

  1. Open the Control Panel.

  2. Select System and maintenance.

  3. Under Administrative tools, select Event Viewer.

    Note:   Select Continue if you receive a message stating that Windows needs your permission to continue.  [cautionend]

  4. In the tree view, select Windows logs.

  5. Select 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. Under Administrative tools, select Event Viewer.

    Note:   Select Continue if you receive a message stating that Windows needs your permission to continue.  [cautionend]

  4. In the tree view, select Windows logs.

  5. Select Application log.


Accessing the Application Log Using Windows Server 2003

Using Windows Server 2003, you access the Application Log from the Event Viewer tree view:

  1. Select Start [arrow] Settings [arrow] Control Panel.

  2. Double-click Administrative Tools.

  3. Double-click Event Viewer.

  4. In the Tree view, select Application Log.

An alternate method of starting the Event Viewer is to type eventvwr in the Run dialog box and click OK.


Accessing the Application Log Using Windows XP

Using Windows XP, you access the Application Log from the Event Viewer tree view:

  1. Select Start [arrow] Control Panel.

  2. Double-click Administrative Tools.

  3. Double-click Event Viewer.

  4. In the Tree view, select Application Log.

An alternate method of starting the Event Viewer is to type eventvwr in the Run 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 will appear 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 will appear 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 will display the message in the Description box.

Displaying a User Message in The Event Detail Dialog Box

[Displaying a user message in the Event Detail dialog box]

For information about LOGEVENT.EXE, see the documentation for the Windows Resource Kit.

Previous Page | Next Page | Top of Page