BookmarkSubscribeRSS Feed
ASASProgrammer
Calcite | Level 5

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

5 REPLIES 5
SASKiwi
PROC Star

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.  

ASASProgrammer
Calcite | Level 5

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...

FriedEgg
SAS Employee

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

Peter_C
Rhodochrosite | Level 12

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.

Patrick
Opal | Level 21

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.

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
  • 1087 views
  • 0 likes
  • 5 in conversation