Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SAS检查目录是否存在_Sas - Fatal编程技术网

SAS检查目录是否存在

SAS检查目录是否存在,sas,Sas,如何检查目录是否存在,如果不存在,则为:syserr 0?,我需要 %sysfunc(filename(fileref,&dir)) 如果存在,我需要syserr值。如果不是0,则需要syserr值。 感谢您的帮助可能有一种更干净的方法让SAS抛出错误,但以下方法对我有效。一般的想法是,如果目录存在,您可以执行某些操作,将syserr设置为0;如果不是,你做了一些会抛出错误的事情 %let your_path = "..."; %macro your_macro(dir);

如何检查目录是否存在,如果不存在,则为:syserr 0?,我需要

%sysfunc(filename(fileref,&dir)) 
如果存在,我需要syserr值。如果不是0,则需要syserr值。
感谢您的帮助

可能有一种更干净的方法让SAS抛出错误,但以下方法对我有效。一般的想法是,如果目录存在,您可以执行某些操作,将syserr设置为0;如果不是,你做了一些会抛出错误的事情

%let your_path = "...";

%macro your_macro(dir);

    %let rc = %sysfunc(filename(fileref, &dir.));

    %if %sysfunc(fexist(&fileref)) %then %do;
        data _null_;
            set _null_;
        run;
    %end;
    %else %do;
        data _null_;
            set something_that_doesnt_exist;
        run;
    %end;

    %put syserr = &syserr.;

%mend your_macro; 

%your_macro(&your_path.);

检查文件夹是否存在的更干净的方法

%let does_it_exist=%sysfunc(fileexist(&dir));

如果文件夹不存在,则返回值0;如果文件夹存在,则返回值1。

如果您使用谷歌搜索“SAS检查目录是否存在”,则返回大量选项。我始终使用syserr=0,即使我尝试对不存在的目录使用dopen函数。然后我有信息
操作的结果被设置为缺少的值。
为什么是SYSERR而不是其他宏变量?不过OP需要SYSERR值1,而不仅仅是宏变量1。fileexist=1也可以表示它是文件,而不是目录。