Hi
I have to implement concurrent write access to a SAS table (control table) without SAS\Share (not licensed) – SAS9.2 under UNIX.
I have in principal a working solution based on the %trylock macro as documented under
http://www.lexjansen.com/pharmasug/2005/posters/po33.pdf
My problem is:
In case the table is locked the macro throws an error. Also that execution goes on and everything works I can’t accept Error messages in the log nor a job to end different than with an Error condition of zero.
I can’t figure out how to achieve this suppression of Errors – especially the ones written to the log.
I could save the error status at the beginning of the macro and re-set it at the very end of the macro – but what should I do with the log?
Any suggestions would be really welcome (it starts to drive me nuts)!
The way I test the macro is to open 2 SAS session. In the first one I open the table used for testing (sashelp.class), in the second session I call the macro as below (and then I go back to the first session and close the table).
%macro trylock(member=,timeout=10,retry=1);
%local starttime;
%let starttime = %sysfunc(datetime());
%do %until(&syslckrc LE 0
or %sysevalf(%sysfunc(datetime()) GT (&starttime + &timeout)));
%put trying open ...;
data _null_;
dsid = 0;
do until (dsid GT 0 or datetime() GT (&starttime + &timeout));
dsid = open("&member");
if (dsid = 0) then rc = sleep(&retry);
end;
if (dsid GT 0) then rc = close(dsid);
run;
%put trying lock ...;
lock &member;
%put syslckrc=&syslckrc;
%end;
%mend trylock;
%trylock(member=sashelp.class,timeout=60,retry=5);
lock sashelp.class clear;
The macro as given above is exactly what has been published in the link given.
The error I'm getting if a table is locked:
trying lock ...
ERROR: A lock is not available for SASHELP.CLASS.DATA.
syslckrc=70031
As soon as I unlock the table in my other SAS session the following happens:
trying lock ...
NOTE: SASHELP.CLASS.DATA is now locked for exclusive access by you.
syslckrc=0
36
37 lock sashelp.class clear;
NOTE: SASHELP.CLASS.DATA is no longer locked by you.
So as already described: The macro works as such but I end up with Errors which shouldn't be there.
It's the LOCK statement causing the issues and I still haven't found a way to capture the error conditions.
Thanks in advance
Patrick
Message was edited by: Patrick
Message was edited by: Patrick