Monday, November 27, 2017

Hack 7.1 Avoiding File Lock Problems



SAS Programming Professionals,

Did you know that you can avoid those occasional, sporadic, annoying file lock wait errors on SAS for Windows by using a simple LIBNAME option?

Occasionally on SAS for Windows, the Microsoft DFS replication process unintentionally causes a lock on SAS data sets.  SAS does not wait for the lock to be released on the SAS data set and displays an error in the SAS log.  For Example:

libname timing "r:\path" ;

Proc sort data = timing.studyfil; 
by fncl_ast_id; 
run;

…could possibly produce the following error:

ERROR: A lock is not available for TIMING.STUDYFIL.DATA.

This happens because locks from third party software applications are not automatically checked by SAS’s internal FILELOCKWAIT facility. This particular error has occasionally been observed when the path to the SAS data library goes to a network drive, not to a C-drive.

To avoid this problem, use the libname option FILELOCKWAIT as follows:

libname timing "r:\path" filelockwait=10;


Note that filelockwait=  is in seconds and in most cases 10 seconds is enough. Also, don’t fret if you have never experienced this issue.  It is relatively rare and has not affected most SAS programmers.  But, now you are sufficiently armed in case you do encounter it.

Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

1 comment:

  1. Hi Michael,

    Thanks for the working example of FILELOCKWAIT in the Libname statement. I have been unable to get FILELOCKWAIT work as a SAS system option via sasv9.cfg, but at the Libname level it works fine.

    A client that I work for has recently started to experience lock errors on SAS datasets and catalogs, which I suspect is due to some system related processes going on in the early hours when their ETL jobs are running. I am going to suggest that they look at using FILELOCKWAIT.

    Thank you.

    Downunder Dave
    Wellington

    ReplyDelete