Back to Tech Corner
SAS Admin

How to Find & Resolve File Lock on WIN Environment

Sometimes users run into error where their jobs end due to their target SAS data set being locked. In this article we will describe some of the troubleshooting steps and techniques used to find and resolve the issue.

Error message showing file lock issue

Troubleshooting Steps

There are multiple methods that you could try to avoid file locks. Typically datasets are locked when a process is writing to them, or when another process is reading the data with a table-level lock. First step would be to check if that is the case:

  1. Extend file lock release wait period by using filelockwait option in your libname if you have somewhat control of jobs trying to update same source at the same time. Check EG option (cross check filelockwait value to be greater than EG option
    Options under Tools in SAS EG

    Options under Tools in SAS EG

  2. Usually SAS Enterprise Guide closes all open data sets before running a program or task to avoid such contention(s), however, for any unforeseen reasons a data set may remain open. A SAS EG option in EG 7.x version is available to ensure that all open data sets are shown
    Image from SAS Doc

    Image from SAS Doc

    However in latest SAS EG 8.x versions there is an option which unlocks all open datasets before running code. This option is available at Tools > Options > Data > Performance

    In SAS EG 8.1 and higher

    In SAS EG 8.1 and higher

  3. Some have tried in their code at the beginning to read in the data in to their temp/WORK and then reference a local copy (I have not tried it)
  4. Try to find any hung code or still active code/session (EG or batch) that may be accessing the said data source.

In some cases often a file or data set needs to be deleted programmatically and the job fails due to a lock preventing access. Note that in this case the target file or data set could be accessed just not deleted. Following are the troubleshooting steps to determine why a file (often created by the owner) is not deleted in the code run by the owner or team members.

WINDOWS

  1. First check permissions of the target object. In WINDOWS environment navigate to the target object location → (right click) → Properties → Security (tab), review the listed permissions for the ID that is running the code, at minimum, the ID should have Read, Write, Modify, Delete privileges.
    Target location via File Explorer

    Target location via File Explorer

    Sample permission Listing

    Sample permission Listing

    In such cases the permissions and group permissions are appropriate

Linux

Linux systems it is much straight forward to list permissions, on the command line navigate to the path where the target object resides and submit command:

cd /some/path/of/target/object/folder  #target object in this folder

ls -l ./target-object  #lists permissions
sample output

sample output

In cases where the permissions check clearly show that valid permissions are present then most probably there is some process that has a lock on the target object and is not allowing the owner of the target object to delete the object let alone any appropriate team member.

We will discuss our preferred method on WINDOWS environment to find such active process and remove it. Comparatively, finding such permission issues or a process ID (PID) is easier on a LINUX environment and which we will discuss in an upcoming article.

Find Active PID on WIN Environment-Preferred Technique

  1. Log on to the server preferably with administrator ID
  2. Start Task Manager (click on appropriate prompts to get through the UAC prompts) 'Run as Administrator'
  3. Click on Performance tab → click on 'Resource Monitor' at the bottom
    Bring up Resource Monitor

    Bring up Resource Monitor

  4. Resource Monitor interface

Working Example:

Working example showing PID identification

Steps to find the PID that has a lock

  1. Open Resource Monitor
  2. Find all "sas.exe" process in the "Processes" window (1) and click on checkboxes against 'sas.exe'
  3. Review window (2) under Associated Handles and find the target object listing and its associate PID, note the PID (10376 in our case)
  4. In Task Manager click on the "Details" tab and locate the offending PID (10376)
  5. Right click on the row with the PID and select "End Process Tree"

Once the process in question is removed, test code again and this time the sas code will be successful.