The LOCK statement enables you to acquire and release an exclusive lock on an existing SAS® file. To determine whether a lock can be obtained, execute the MODIFY statement within a DATA step, because it requires a lock on the data set in Update mode.
/* Set macro variable LOCKED to a value of 'yes' */ %let locked=yes; /* Use a MODIFY statement to determine if the data set is locked */ /* since it requires locking the data set in update mode at the */ /* observation level. In order to lock the data set at the member */ /* level, use the CNTLLEV= option. */ data library.data_set_name; modify lib.a(cntllev=mem); /* If the data set is not locked, the following CALL SYMPUTX */ /* will run and set &LOCKED to 'no'. */ call symputx('locked','no'); stop; run;
If you were unable to obtain a lock but want to continue trying to obtain that lock for a period of time, use the code below. The code uses the SLEEP function to attempt a lock periodically.
/* The SLEEP function is used to wait for a lock to be obtained. */ /* You set the number of seconds that the lock should continue to */ /* be attempted with the TIMEOUT= parameter. */ libname test 'path_to_SAS_data_library'; /* Create a test data set */ data test.f1; infile datalines; input a b; datalines; 1 2 3 4 5 6 7 8 ; run; /* Options to help debug the macro */ options mprint mlogic symbolgen; %macro trylock(member=, timeout=); %local starttime; %let starttime = %sysfunc(datetime()); %do %until (&syslckrc = 0 or %sysevalf(%sysfunc(datetime()) > (&starttime + &timeout))); %put trying to open ...; %put trying lock ...; lock &member; %if &syslckrc ne 0 %then %let rc=%sysfunc(sleep(15)); %put syslckrc=&syslckrc; %end; %mend trylock; %trylock(member=test.f1, timeout=600); proc print data=test.f1; run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Topic: | SAS Reference ==> Statements ==> Statements |
Date Modified: | 2013-11-07 13:36:38 |
Date Created: | 2013-10-07 21:22:34 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | Aster Data nCluster on Linux x64 | ||
DB2 Universal Database on AIX | ||||
DB2 Universal Database on Linux x64 | ||||
Greenplum on Linux x64 | ||||
Netezza TwinFin 32bit blade | ||||
Netezza TwinFin 32-bit SMP Hosts | ||||
Netezza TwinFin 64-bit S-Blades | ||||
Netezza TwinFin 64-bit SMP Hosts | ||||
Teradata on Linux | ||||
z/OS | ||||
Z64 | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Pro | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |