DATA Step, Macro, Functions and more

A function to tackle "FILE LOCKING"

Reply
Contributor
Posts: 36

A function to tackle "FILE LOCKING"

Hello,

 

Could someone please suggest me a method/function that helps SAS not to stop/terminate when a non sas file like a LOG file is in use. The LOG file is not used/opened by me, I guess Windows or some third party app is doing it. Any suggestion would be of great use. 

 

Thanks. 

Super User
Posts: 19,770

Re: A function to tackle "FILE LOCKING"

Why would your SAS log file be locked? Virus scanner? 

Contributor
Posts: 36

Re: A function to tackle "FILE LOCKING"

Thanks Reeza for the reply. Seriously I have no idea why it gets locked. I do not think its a virus scanner coz, this happens only to a "constant" couple of programs.
PROC Star
Posts: 1,759

Re: A function to tackle "FILE LOCKING"

How do you use the file? is it a log file you write to via proc printto? or is this log file an input file that you need reading?

Contributor
Posts: 36

Re: A function to tackle "FILE LOCKING"

Its a log file that I get from running SAS in BATCH. I do not use/read it other than in notepad++ to check where/how the program is. 

Super User
Posts: 19,770

Re: A function to tackle "FILE LOCKING"


niranvijay wrote:

Its a log file that I get from running SAS in BATCH. I do not use/read it other than in notepad++ to check where/how the program is. 


So you open the log file in Notepad++ and then SAS throws an error because it's locked? What happens if you don't open file while process is running? Do you still get a File Lock?

Contributor
Posts: 36

Re: A function to tackle "FILE LOCKING"

Reeza,

Not really. I look at the log only after the program has finished running. But I have the program itself opened in NOTEPAD++. But this file locking started to happen very recently. I know that Notepad++ dont keep a lock on the file, but still?. The worst part is that It happens randomly(days) to the same program. 

 

Thanks

Super User
Posts: 7,762

Re: A function to tackle "FILE LOCKING"

If a file is explicitly locked for any type of access (not just write/update), there's nothing you can do except identify the process that holds the lock, and then terminate it.

 

Which is a very rude way to go about it. (And you need to have the rights/permissions to do this. I have found that the execrable Windows does not really have a "superuser" type UserID like UNIX. Even "the" Administrator is often unable to to stop a process, short of restarting the system.)

 

So, after having identified the offending process with operating system tools, check why the file is locked. If there is an update underway at the moment SAS tries to read the file, the lock is quite natural. In this case you have to set up time windows during which the file will not be updated so SAS can safely read it.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 36

Re: A function to tackle "FILE LOCKING"

Posted in reply to KurtBremser

Kurt,
Could you please tell me what you meant by "In this case you have to set up time windows during which the file will not be updated so SAS can safely read it."

 

Thanks

Super User
Super User
Posts: 7,942

Re: A function to tackle "FILE LOCKING"

Just going to ad to the great advice above, encountering file locks should be almost never.  If you are finding files locked then you have a structural or process fault.  For instance, if you have users who use the data, then don't have them doing that in the production branch, otherwise when you try to run production you will encounter this.  A way of seperating users working areas out from production (which should be run at fixed - known times) shuld remove file lock issues.

Contributor
Posts: 36

Re: A function to tackle "FILE LOCKING"

I agree with what you have said,RW9. But in my case I have no idea why the log file gets locked. If I know that some app/OS is holding the lock, then I can manually terminate it. 

 

Thanks

Super User
Super User
Posts: 7,942

Re: A function to tackle "FILE LOCKING"

Speak to your IT team, they will help finding out what application is locking the file.  Text files generally don't get locked, so that is unusual.  That being said, my company has applications running the background which mirror files off to a backup, and that sometimes prevents me deleting files or folders, so it could be something like that.  Its a system thing though, not really a SAS problem.

Contributor
Posts: 36

Re: A function to tackle "FILE LOCKING"

Thanks again RW9

PROC Star
Posts: 1,759

Re: A function to tackle "FILE LOCKING"

Sadly this is a system issue. If you ask sas to use a file and the file is locked, sas will complain. You must fix this at the system level. Utilities like process explorer can tell you what processes use what file handles.
Contributor
Posts: 36

Re: A function to tackle "FILE LOCKING"

Thanks ChrisNZ for your suggestion.

Ask a Question
Discussion stats
  • 14 replies
  • 389 views
  • 0 likes
  • 5 in conversation