我基本上已根据您的要求修改了此链接中可用的代码.我还添加了一些代码来修复由于引号和管道命令而面临的问题.基本上你应该让SAS在传递代码之前处理引号.
%macro windows_bytes_free(sm_path);
%global mv_bytes_free;
%let mv_bytes_free = -1; /* In case of error */
%let filepath = %sysfunc(quote(%qsysfunc(dequote(&sm_path)))); /* To prevent issues with quotes remove quotes if present and apply it again*/
/* Run the DIR command and retrieve results using an unnamed pipe */
filename tempdir pipe %sysfunc(quote(dir /-c &filepath | find "bytes free")) ;
data _null_;
infile tempdir length=reclen ;
input line $varying1024. reclen ;
re = prxparse('/([0-9]+) bytes/'); /* Parse the output of DIR using a Perl regular expression */
if prxmatch(re, line) then do;
bytes_str = prxposn(re, 1, line);
bytes = input(bytes_str, 20.);
call symput('mv_bytes_free', bytes); /* Assign available disk space in bytes to a global macro variable */
kb = bytes /1024;
mb = kb / 1024;
gb = mb / 1024;
format bytes comma20.0;
format kb mb gb comma20.1;
/* Write a note to the SAS log */
put "NOTE: &sm_path " bytes= kb= mb= gb=;
if gb<1 then put '** Available space is less than 1 gb';
else put '** Enough space is available';
end;
run;
%if &mv_bytes_free eq -1 %then %put ERROR: error in windows_bytes_free macro;
%mend;
Run Code Online (Sandbox Code Playgroud)
如何将此宏用于C:驱动器的示例
%windows_bytes_free(c:);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1718 次 |
最近记录: |