Good morning.
is there a code to check if there is a lock on a sas table? that is, if it is already open.
Thank you
This paper has a sample macro that will provide the functionality you are looking for
Play Nice with Others: Waiting for a Lock on SAS Table
Hope this helps
Thanks, but I just need a code to check if a table is locked or not
@mariopellegrini wrote:
Thanks, but I just need a code to check if a table is locked or not
The LOCK statement can LIST the status.
lock lib.member list;
will show message in the log similar to:
NOTE: LIB.MEMBER.DATA is not locked or in use by you or any other users.
or other lock status.
The Lock statement also sets a value for the system macro variable SYSLCKRC . Automatic macro variable value will be 0 if the last lock statement is successful. >0 if the lock statement is not successful. So one use is to attempt to Lock the file and if it fails, i.e. you can't get a lock, assume it is already locked. Verify the existence of the member first though.
Remember to CLEAR the lock if successful in acquiring the lock.
There are other behaviors that depend on use of products like SAS/SHARE and I'm not sure about other products.
This paper suggests that the LOCK statement isn't necessarily reliable if you don't have SAS/SHARE.
https://support.sas.com/resources/papers/proceedings17/1465-2017.pdf
the SYSLCKRC variable gives me a value greater than zero even keeping the table open. with the lock lib.member list statement I can't "capture" the value obtained in a variable...
If this should be part of an update process, and your SAS runs on UNIX, you can simply delete the dataset file before you write the new dataset.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.