LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2005, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 25 May 2005 15:26:31 -0700
Reply-To:   cassell.david@EPAMAIL.EPA.GOV
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject:   Re: Error: File is in Use
In-Reply-To:   <200505252053.j4PKrFss009334@listserv.cc.uga.edu>
Content-type:   text/plain; charset=US-ASCII

Rick Andrews <richard.andrews@CMS.HHS.GOV> wrote: > I found this code on SAS-L to prevent a file from being opened if it > already being used. I'm trying to do this to prevent an evil "FILE IN USE" > message, which kicks the program into syntax check mode. > > This code does not seem to work for me on the mainframe. Any ideas? > > Muchas gracias! > > filename prodfile "&PRODFILE"; > data _null_; > inuse = fopen('prodfile'); > call symput('INUSE',inuse); > if inuse = 0 then do; > put '*** Attention: the file below was in use ***'; > put "&PRODFILE"; > put '*** Attention: the file above was in use ***'; > end; > run; > %IF &INUSE NE 0 %THEN %DO;

A couple things come to mind. For one thing, if you use FOPEN() in z/OS, you have to use FCLOSE() at the end of the DATA step, or else the file stays open. SAS doesn't automatically close the files after processing. I think OpenVMS has the same constraint.

A more subtle issue could be the fact that this test is not atomic (in the comp sci sense of the word). It is feasible that your test will find the file available, but then before you can open it for processing, some other program could come in and snag it, thus giving you the same old "FILE IN USE" message you have come to know and love. If this could happen, then perhaps you want to do all your processing in one single data step, using FOPEN() to test the file, while at the same time opening it for reading later in the data step using FREAD() and then processing of the File Data Buffer, before ending the data step with the requisite FCLOSE().

HTH, David -- David Cassell, CSC Cassell.David@epa.gov Senior computing specialist mathematical statistician


Back to: Top of message | Previous page | Main SAS-L page