Help using Base SAS procedures

Detecting an existing lock on external output file

Reply
N/A
Posts: 0

Detecting an existing lock on external output file

Hi, we create a lot of excel and text files that are picked up by users. From time to time someone will have the file open when we are trying to overwrite it, which generates the following error in the log :
ERROR: File is in use, \\svrbu3file\etc........

I'm looking for a way of trapping this error and doing something in the code when it occurs. I tried checking syscc but it is still 0. Has anyone else had this problem or anyone able to offer a suggestion?

Thanks.
N/A
Posts: 0

Re: Detecting an existing lock on external output file

Posted in reply to deleted_user
Further investigation shows a proc export will set the syscc to 1012 however when using ods syscc is still 0.

Naturally it is ods that we are using Smiley Sad

So if you know a way to check a file in use when creating a file using ods .... Smiley Happy
Super Contributor
Posts: 474

Re: Detecting an existing lock on external output file

Posted in reply to deleted_user
Try to open the file through the external file functions, for example like this:

%let FILENAME=D:\temp\Teste.xls;
data _null_;
RC=filename('MYFILE',"&FILENAME");
FID=fopen('MYFILE','I');
if not FID then put "File &FILENAME is in use!";
else put "File &FILENAME opened successfully.";
RC=fclose(FID);
run;

FOPEN functions returns a file identifier (non zero integer) if the file was opened successfully.

See more on this here:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000209683.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
Ask a Question
Discussion stats
  • 2 replies
  • 131 views
  • 0 likes
  • 2 in conversation