BookmarkSubscribeRSS Feed
DG1984
Fluorite | Level 6

I am using the below macro to check for a lock every 15 seconds for 30 minutes. 

 

%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;

 

if the file is locked the macro will keep running either for 30 minutes or until a lock is available.  It will write to the log every time it attempts to lock the file

 

Below is an example

 

ERROR: A lock is not available for <Data>

syslckrc=70031

trying to open ...

trying lock ...

ERROR: A lock is not available for <Data>

syslckrc=70031

trying to open ...

trying lock ...

NOTE: <Data>  is now locked for exclusive access by you.

syslckrc=0

17        

 

Is there a way I can just get the last entry written to the log rather than all entries?

 

5 REPLIES 5
Quentin
Super User

There is a NOMSG option for the LOCK statement that seems to do what you want:

 

Tip NOMSG is useful if you want a LOCK statement resubmitted in a code loop until a lock is available, but you do want error messages displayed in the SAS log each time that an exclusive lock is not available.

 

 

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
DG1984
Fluorite | Level 6

Thanks will investigate!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why do you need to do this in the first place.  Errors are in the log to tell you something is going wrong, therefore the best solution is to fix what is going wrong.  

DG1984
Fluorite | Level 6

The code is trying to lock a dataset in a loop so it may have errors but eventually it may work, if it does work I don't need to know about the errors which is why I am looking for something that only writes the last try to the log rather all versions.   

Ksharp
Super User

LIBNAME statement has an option FILELOCK something like . Maybe could apply to your scenario .

sas-innovate-wordmark-2025-midnight.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. Sign up by March 14 for just $795.


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
  • 5 replies
  • 1496 views
  • 2 likes
  • 4 in conversation