DATA Step, Macro, Functions and more

Supress Errors from the log

Reply
Occasional Contributor
Posts: 8

Supress Errors from the log

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?

 

PROC Star
Posts: 1,434

Re: Supress Errors from the log

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.

 

 

Occasional Contributor
Posts: 8

Re: Supress Errors from the log

Thanks will investigate!

Super User
Super User
Posts: 9,227

Re: Supress Errors from the log

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.  

Occasional Contributor
Posts: 8

Re: Supress Errors from the log

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.   

Super User
Posts: 10,621

Re: Supress Errors from the log

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

Ask a Question
Discussion stats
  • 5 replies
  • 149 views
  • 2 likes
  • 4 in conversation