2015-10-08 45 views
1

我在文件服务器上有一个sas-db文件,并且想检查它是否由另一台PC打开。SAS检查文件服务器上的文件是否被其他PC打开

我试了几次尝试使用此源http://www.wuss.org/proceedings11/Papers_Galligan_O_74889.pdfhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0a6vn2td7bjr2n1viy8y4lgvq61.htm没有成功。 日志中的数字(fid)永远不会变为0,而不管该文件是否在另一台PC上打开。

%MACRO Try; 

%let filrf=myfile; 
%let rc=%sysfunc(filename(filrf,\\inti\[...]\p3001_overviewsampling.sas7bdat)); 
%let fid=%sysfunc(fopen(&filrf)); 
%PUT RC is: &RC // fid is &fid ; 

%MEND; 
%Try; 

LOG: RC is: 20036 // fid is 30 

任何想法? 谢谢,数据的回答 ----------------

感谢您的休息后Lubenja

------编辑。但是,如果我运行两次宏,则不再有效。即使从同一台PC运行,文件也会被锁定。现在我不能从任何一台PC上删除文件。

17 %LET Path =\\hugo\Temp; 
18 LIBNAME test "&Path"; 
NOTE: Libref TEST was successfully assigned as follows: 
     Engine:  V9 
     Physical Name: \\hugo\Temp 
19 
20 
21 data test.class2; 
22   set sashelp.class; 
23 run; 

NOTE: There were 19 observations read from the data set SASHELP.CLASS. 
NOTE: The data set TEST.CLASS2 has 19 observations and 5 variables. 
NOTE: DATA statement used (Total process time): 
     real time   0.06 seconds 
     cpu time   0.01 seconds 


24 
25 %MACRO Try(data=,library=); 
26  %let filrf=myfile; 
27  %let rc=%sysfunc(filename(filrf,%sysfunc(pathname(&library))/&data..sas7bdat)); 
28  %let fid=%sysfunc(fopen(&filrf,O)); 
29  %PUT RC is: &RC // fid is &fid ; 
30  %if &fid %then %let rc=%sysfunc(fclose(&fid)); 
31 %MEND; 
32 %Try(data=class2,library=test); 
RC is: 0 // fid is 1 

33 %Try(data=class2,library=test); 
RC is: 0 // fid is 0 

34 data test.class2; 
35   set sashelp.class; 
36 run; 

ERROR: An I/O error has occurred on file TEST.CLASS2.DATA. 
NOTE: The SAS System stopped processing this step because of errors. 
NOTE: DATA statement used (Total process time): 
     real time   0.01 seconds 
     cpu time   0.01 seconds 
+0

如果你是想为了写它看看这个答案HTTP来锁定一个SAS数据集://计算器。 com/a/17871132/214994。 –

回答

0

我不得不添加的O输出选项F打开

25   data class; 
26   set sashelp.class; 
27   run; 

NOTE: There were 19 observations read from the data set SASHELP.CLASS. 
NOTE: The data set WORK.CLASS has 19 observations and 5 variables. 
NOTE: DATA statement used (Total process time): 
     real time   0.02 seconds 
     cpu time   0.01 seconds 


28   %let did = %sysfunc(open(class)); 
29   %put &=did; 
DID=1 
30   
31   %MACRO Try(data=); 
32   %let filrf=myfile; 
33   %let rc=%sysfunc(filename(filrf,%sysfunc(pathname(work))/&data..sas7bdat)); 
34   %let fid=%sysfunc(fopen(&filrf,O)); 
35   %PUT RC is: &RC // fid is &fid ; 
36   %if &fid %then %let rc=%sysfunc(fclose(&fid)); 
37   %MEND; 
38   %Try(data=class) 
Resource is read-locked by another thread. File 
=/opt/local/saswork/...redacted.../class.sas7bdat. 
RC is: 0 // fid is 0 
39   
40   %let rc=%sysfunc(close(&did)); 
41   %put &=rc; 
RC=0 
+0

谢谢你的安息。但是,如果我运行两次宏,则不再有效。不知怎的,文件被锁定。 请在我的问题中看到上面的细节。 – lubenja