【问题标题】:SAS check if file on fileserver is opended by other PCSAS检查文件服务器上的文件是否被其他PC打开
【发布时间】:2018-10-01 00:32:30
【问题描述】:

我在文件服务器上有一个 sas-db 文件,想检查它是否被另一台 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

有什么想法吗? 谢谢,鲁本贾

----- 数据回答后编辑 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

【问题讨论】:

标签: file sas


【解决方案1】:

我必须将 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

【讨论】:

  • 感谢您的休息。但是,如果我运行你的宏两次,它就不再工作了。不知何故,文件被锁定。请在我的问题中查看上面的详细信息。
【解决方案2】:

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

%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;

【讨论】:

    猜你喜欢
    • 2012-06-22
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 2016-02-29
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多