BookmarkSubscribeRSS Feed
mariopellegrini
Pyrite | Level 9

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

6 REPLIES 6
AhmedAl_Attar
Ammonite | Level 13

Hi @mariopellegrini 

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

mariopellegrini
Pyrite | Level 9

Thanks, but I just need a code to check if a table is locked or not

ballardw
Super User

@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.

Quentin
Super User

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

 

 

mariopellegrini
Pyrite | Level 9

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...

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3074 views
  • 2 likes
  • 5 in conversation