Controlling Data in the Audit Trail

Overview

Now that you have seen how to initiate audit trails and read an audit trail file, consider the information the audit trail file contains. The audit trail file can contain three types of variables:
  • data set variables that store copies of the columns in the audited SAS data set
  • audit trail variables that automatically store information about data modifications
  • user variables that store user-entered information
Controlling Data in the Audit Trail
You can use additional statements in the PROC DATASETS step to control which variables appear in the audit trail. We consider each of the three types of variables that can be found in an audit trail.

Data Set Variables

As you might expect, the audit trail file has the same set of variables that are in the audited data set. If the data set contains the variables A and B, the variables A and B are also in the audit trail file.
Next consider the audit trail variables that automatically store information about changes that you make to the data.

Audit Trail Variables

Audit trail variables automatically store information about data modifications. Audit trail variable names begin with AT followed by a specific string, such as DATETIME.
Audit Trail Variable
Information Stored
_ATDATETIME_
date and time of a modification
_ATUSERID_
login user ID associated with a modification
_ATOBSNO_
observation number affected by the modification unless REUSE=YES
_ATRETURNCODE_
event return code
_ATMESSAGE_
SAS log message at the time of the modification
_ATOPCODE_
code describing the type of operation

Values of the _ATOPCODE_ Variable

The _ATOPCODE_ variable contains a code that describes the type of operation that wrote the observation to the audit file. For example, if you modified all observations in an audited data set, the audit file would contain twice as many observations as the original data set. The audit file would contain one observation that matched the original observation with an _ATOPCODE_ value of DR, and one updated observation with an _ATOPCODE_ value of DW.
Here are the possible values of the _ATOPCODE_ variable.
_ATOPCODE_
Event
DA
added data record image
DD
deleted data record image
DR
before-update record image
DW
after-update record image
EA
observation add failed
ED
observation delete failed
EU
observation update failed
You can define what information is stored in the audit file by using the LOG statement when you initiate the audit trail.

Using the LOG Statement to Control the Data in the Audit Trail

When you initiate an audit trail, options in the LOG statement determine the type of entries that are stored in the audit trail, along with their corresponding _ATOPCODE_ values. The ERROR_IMAGE option controls E operation codes. The BEFORE_IMAGE option controls the DR operation code, and the DATA_IMAGE option controls all other D operation codes. If you omit the LOG statement when you initiate the audit trail, the default behavior is to log all images.
General form, LOG statement:
LOG <audit-settings>;
Here is an explanation of the syntax:
audit-settings
are any of the following:
  • BEFORE_IMAGE=YES|NO controls storage of before-update record images (the 'DR' operation).
  • DATA_IMAGE=YES|NO controls storage of after-update record images (for example, other operations starting with 'D').
  • ERROR_IMAGE=YES|NO controls storage of unsuccessful update record images (for example, operations starting with 'E').

Example

The following code initiates an audit trail on the data set Capinfo but stores only error record images. This means that the audit file contains only records where an error occurred. The _ATOPCODE_ values can be only EA, ED, and EU.
Note: If you choose to run this example, you must copy the data set Capinfo from the Sasuser library to the Work library.
proc datasets nolist;
   audit capinfo;
   initiate;
   log data_image=NO before_image=NO;
quit;

User Variables

User variables allow the person editing the file to enter information about changes that they are making to the data. Although the data values are stored in the audit file, you can update them in the data set like any other variable.
User variables are created by using the USER_VAR statement in the audit trail specification.
General form, USER_VAR statement:
USER_VAR variable-name <$><length><LABEL='variable-label'>;
Here is an explanation of the syntax:
variable-name
is the name of the user variable that you are creating.
$
indicates the variable is a character variable.
length
specifies the length of the variable (the default is 8).
variable-label
specifies a label for the variable enclosed in quotation marks.
Note: You can create more than one user variable in a single USER_VAR statement.
User variables are unique in SAS in that they are stored in one file (the audit file) and opened for update in another file (the data set). When the data set is opened for update, the user variables are displayed, and you can edit them as if they are part of the data set.

Example

Suppose you must monitor the updates for the data set Capinfo. The following code initiates an audit trail for the data set Capinfo and creates two user variables, who and why, to store who made changes to the data set and why the changes were made.
Note: If you choose to run this example, you must copy the data set Capinfo from the Sasuser library to the Work library.
proc datasets nolist;
   audit capinfo;
   initiate;
   user_var who $20 label = 'Who made the change'
            why $20 label = 'Why the change was made';
quit;
Once these user variables are set up, they are retrieved from the audit trail and displayed when the data set is opened for update. You can enter data values for the user variables as you would for any data variable. The data values are saved to the audit trail as each observation is saved. The user variables are not available when the data is opened for browsing or printing. To rename a user variable or modify its attributes, you modify the data set, not the audit file.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.235.188