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

 

 

The Boston Area SAS Users Group is hosting free webinars!
Next up: Rick Wicklin presents Ten Tips for Effective Statistical Graphics (with SAS code) on Wednesday March 26.
Register now at https://www.basug.org/events.
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...

sas-innovate-white.png

Register Today!

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.

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
  • 2387 views
  • 2 likes
  • 5 in conversation