Locking Explicitly in a SAS Window (LOCK Command)

Advantages of Using the LOCK Command

The LOCK command provides a convenient way to lock data objects that are in a SAS window. As with the LOCK statement, you can use the LOCK command to obtain an explicit lock on data libraries, data sets, catalogs, and catalog entries.
You can specify the name of the data object that is to be locked on the command line of a window, such as the Program Editor window.
Note: You must first access a SAS library through a server before you can lock that library or any data object in it.

Syntax for the LOCK Command

LOCK libref<.member-name<.member-type | .entry-name.entry-type>>
<LIST | CLEAR>;
libref
is the name that is temporarily associated with a SAS library.
member-name
is the name that specifies a member of the referenced data library.
member-type
is the type of SAS file to be locked. Valid values include DATA, VIEW, and CATALOG. The default is DATA.
If you omit member-type or if you specify either the value DATA or VIEW, two locks are obtained automatically: one on libref.member-name.DATA and one on libref.member-name.VIEW.
entry-name.entry-type
is the name and type of the SAS catalog entry to be locked.
LIST
writes to the SAS log whether the specified data object is locked and by whom. This argument is optional.
CLEAR
releases a lock on a specified data object that was acquired in your SAS session by using the LOCK command. This argument is optional.
For details about releasing locks, see Clearing an Explicit Lock.

Locking and Clearing Locks on Data Objects

You can issue the LOCK command in any SAS window. It works exactly like the LOCK statement. For details about the LOCK statement, see The LOCK Statement and Command.
The following SAS log shows the message in the Log window that lets you know that the catalog MAPSLIB.MAPSCAT.EUROMAP.CMAP has been locked successfully. In the Program Editor window, the LOCK command was issued to obtain a lock on the catalog MAPSLIB.MAPSCAT.EUROMAP.CMAP.
Locking a Catalog Entry

   LOG
    Command ===>

    1   LIBNAME MAPSLIB 'SASXYZ.SHRTEST.SASDATA' SERVER=SHARE1;
    NOTE: Libref MAPSLIB was successfully assigned as follows:
          Engine:        REMOTE
          Physical Name: SASXYZ.SHRTEST.SASDATA
    NOTE: MAPSLIB.MAPSCAT.EUROMAP.CMAP is now locked for 
          exclusive access by you.

   PROGRAM EDITOR
    Command ===> LOCK  MAPSLIB.MAPSCAT.EUROMAP.CMAP

    00001
    00002
    00003
    00004
    00005
    00006
The following Program Editor window shows a LOCK command that contains the argument CLEAR to release the lock on the catalog MAPSLIB.MAPSCAT.EUROMAP.CMAP.
Releasing a Lock on a Catalog Entry

   PROGRAM EDITOR
    Command ===> LOCK  MAPSLIB.MAPSCAT.EUROMAP.CMAP  CLEAR

    00001
    00002
    00003
    00004
    00005
    00006
In the next SAS log, the messages in the Log window show that MAPSLIB.MAPSCAT.EUROMAP.CMAP was successfully unlocked. The log also displays the name of the user who clears the lock. In this example, the user who set and cleared the lock is referred to as “you.”
SAS Log Message after the Lock Has Been Cleared

   LOG
    Command ===>

    1   LIBNAME MAPSLIB 'SASXYZ.SHRTEST.SASDATA' SERVER=SHARE1;
    NOTE: Libref MAPSLIB was successfully assigned as follows:
          Engine:        REMOTE
          Physical Name: SASXYZ.SHRTEST.SASDATA
    NOTE: MAPSLIB.MAPSCAT.EUROMAP.CMAP is now locked for 
          exclusive access by you.
    NOTE: MAPSLIB.MAPSCAT.EUROMAP.CMAP is no longer locked 
          for exclusive access by you.