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.

 

 

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1064 views
  • 2 likes
  • 4 in conversation