Hi,
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!
Shi
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.
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...
To obtain a lock you can use the lock statement.
data foo;
set sashelp.class;
run;
lock work.foo;
proc datasets lib=work;
change foo=bar;
run;
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
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.
I've tried in the past to make this %trylock() macro work failsafe but with no real success. So can't really recommend to use it.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.