Each time you issue
a SAS statement or a procedure to process a SAS file, the file is
opened for input, update, or output processing. At the end of the
step, the file is closed. In a program with multiple tasks, a file
could be opened and closed multiple times. Because multiple SAS sessions
in a single-user environment can access the same SAS file, issuing
the LOCK statement to acquire an exclusive lock on the file protects
data while it is being updated in a multistep program.
For example, consider
a nightly update process that consists of a DATA step to remove observations
that are no longer useful, a SORT procedure to sort the file, and
a DATASETS procedure to rebuild the file's indexes. If another SAS
session accesses the file between any of the steps, the SORT and DATASETS
procedures would fail, because they require member-level locking (exclusive)
access to the file.
Including the LOCK statement
before the DATA step provides the needed protection by acquiring exclusive
access to the file. If the LOCK statement is successful, a SAS session
that attempts to access the file between steps will be denied access,
and the nightly update process runs uninterrupted. See
Locking a SAS File.