The audit trail is created by the default Base SAS
engine and has the same libref and member name as the data file, but
has a type of AUDIT. It replicates the variables in the data file
and also stores two types of audit variables:
-
_AT*_ variables, which automatically
store modification data
-
user variables, which are optional
variables that you can define to collect modification data
The _AT*_ variables
are described in the following table.
_AT*_ Variables
|
|
|
Stores the date and
time of a modification
|
|
Stores the logon user
ID that is associated with a modification
|
|
Stores the observation
number that is affected by the modification, except when REUSE=YES
(because the observation number is always 0)
|
|
Stores the event return
code
|
|
Stores the SAS log message
at the time of the modification
|
|
Stores a code that describes
the type of modification
|
The
_ATOPCODE_ values are listed in the following table.
_ATOPCODE_ Values
|
|
|
|
|
|
|
|
|
Deleted data record
image
|
|
Before-update record
image
|
|
After-update record
image
|
|
|
|
Observation delete failed
|
|
Observation update failed
|
The type of entries
stored in the audit trail, along with their corresponding _ATOPCODE_
values, are determined by the options specified in the LOG statement
when the audit trail is initiated. Note that if the LOG statement
is omitted when the audit trail is initiated, the default behavior
is to log all images.
-
The A operation codes are controlled
by the ADMIN_IMAGE option.
-
The DR operation code is controlled
by the BEFORE_IMAGE option.
-
All other D operation codes are
controlled with the DATA_IMAGE option.
-
The E operation codes are controlled
by the ERROR_IMAGE option.
The user variable is
a variable that associates data values with the data file without
making them part of the data file. That is, the data values are stored
in the audit file, but you update them in the data file like any other
variable. You might want to define a user variable to enable end users
to enter a reason for each update.
User variables are defined
at audit trail initiation with the USER_VAR statement. For example,
the following code initiates an audit trail and creates a user variable
REASON_CODE for data file MYLIB.SALES:
proc datasets lib=mylib;
audit sales;
initiate;
user_var reason_code $ 20;
run;
After the audit trail
is initiated, SAS retrieves the user variables from the audit trail
and displays them when the data file 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. (In applications that save observations as you scroll through
them, it might appear that the data values have disappeared.) The
user variables are not available when the data file is opened for
browsing or printing. However, to rename a user variable or modify
its attributes, you modify the data file, not the audit file. The
following example uses PROC DATASETS to rename the user variable:
proc datasets lib=mylib;
modify sales;
rename reason_code = Reason;
run;
quit;
You must also define attributes such as format
and informat in the data file with PROC DATASETS. If you define user
variables, you must store values in them in order for the variables
to be meaningful.
A data file can have
one audit file, and the audit file must reside in the same SAS library
as the data file.