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