如何检查一个目录是否已经存在,如果不存在,创建它?如何检查一个目录是否已经存在,如果没有,创建它?
我使用与SAS EG 5.1 SAS 9.3服务器在Windows 7
%macro chk_dir(dir=) ;
options noxwait;
%local rc fileref ;
%let rc = %sysfunc(filename(fileref,&dir)) ;
%if %sysfunc(fexist(&fileref)) %then
%put NOTE: The directory "&dir" exists ;
%else
%do ;
%sysexec md &dir ;
%put %sysfunc(sysmsg()) The directory has been created. ;
%end ;
%let rc=%sysfunc(filename(fileref)) ;
%mend chk_dir ;
此代码来自SAS website。
然而,当我尝试使用这个宏,%chk_dir(dir=E:\foo\20140904_test);
创建一个文件夹,它无法创建文件夹,我得到以下日志消息:
MLOGIC(CHK_DIR): %SYSEXEC md &dir
SYMBOLGEN: Macro variable DIR resolves to E:\foo\20140904_test
ERROR: Shell escape is not valid in this SAS session.
MLOGIC(CHK_DIR): %PUT %sysfunc(sysmsg()) The directory has been created.
目录E:\foo'
确实存在,并呼吁%chk_dir(dir=E:\foo);
给日志输出:如预期的那样,NOTE: The directory "E:\foo" exists
。
我想知道下面是否与此有关:http://support.sas.com/kb/41/058.html – JustinJDavies 2014-09-04 07:30:02
是的,您是正确的:您的服务器管理员可能已禁用XCMD。这是默认情况下,我相信(禁用它),所以它可能不是故意的 - 当然值得问。 – Joe 2014-09-04 15:05:04