10-28-2013 09:48 AM
I need change a SAS data set's name while someone is reading the data from the data set.
It does not matter the renaming interrupts the reading.
How can I acquire the a lock and force to rename the data set?
Thanks in advance!
10-28-2013 04:00 PM
I don't believe this is possible - not without SAS/Share anyway. SAS uses operating system locking. If a SAS dataset is locked while being read, it means the file is locked by the operating system so you can't "force" a lock and rename it.
What operating system are you using? I believe Unix may be more flexible in this area than Windows. If you were using SAS/Share and the dataset was being accessed via a SAS/Share server then I think this might be possible.
10-28-2013 04:39 PM
Thanks for the information.
It is on Unix box.
It might not be a OS level lock.
I tested with a small text file: Open a file with vi in one session, and I still can rename it with mv in another session.
However, even for small SAS data set, when one session reading the data set, it is not allowed to change the name with proc datasets.
It can be renamed with mv using xcmd, but it is not a "pure" SAS way...
10-28-2013 06:21 PM
To obtain a lock you can use the lock statement.
proc datasets lib=work;
lock work.foo clear;
I remember an old paper that contained a macro call %trylock, which you may find useful. You cannot lock a SAS file or modify one by force when a lock is held by another process in SAS.
You could try having the session performing the read use cntllev=rec, but I have not tested it.
I found the paper, I think: http://www.lexjansen.com/pharmasug/2005/posters/po33.pdf
10-28-2013 06:52 PM
the problem is that you cannot stop the current user/use of a table to apply the lock.
What would be nice is a RESERVE type of lock.
Macro %TRYLOCK() is an attempt to obtain a lock. However this is os-dependent - if it doesn't support that functionality. I think there is nothing else to hold that RESERVE-request.