SAS检查文件服务器上的文件是否由其他PC打开

时间:2015-10-08 11:51:37

标签: file sas

我在文件服务器上有一个sas-db文件,想要检查,如果它是由另一台PC打开的。

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

%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

------在数据 null ----------------

的答案之后编辑

谢谢你的安息。但是,如果我运行你的宏两次它不再工作。不管怎样,即使从同一台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

2 个答案:

答案 0 :(得分:0)

我必须将O输出选项添加到FOPEN

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

答案 1 :(得分:0)

以下是处理这种情况的一种方法,尽管不幸的是,它仍然会向日志中写入错误:

%let lib=YOURLIB;
%let ds=YOURDS;

/* first - test for syscc>0 and handle */
/* next, attempt to gain update access and set var if successful */
%let locked=yes;
data &lib..&ds;
  modify &lib..&ds;
  call symputx('locked','no');
  stop;
run;

/* if error, or explicity locked, handle the case */
%if &syscc>0 or &locked=yes %then %do;
  %let syscc=0;
  options obs=max replace nosyntaxcheck;
  /* DO SOMETHING HERE */
%end;