如何使用SAS检查可用磁盘空间

如何使用SAS检查可用磁盘空间,sas,Sas,如何检查驱动器上的剩余空间,以及是否小于1GB,以便使用SAS输出消息。 我只有一个检查SAS文件大小的代码。我基本上已经根据您的要求修改了link中可用的代码。我还添加了一些代码来修复由于引号和pipe命令而面临的问题。基本上,您应该让SAS在传递代码之前处理引号 %macro windows_bytes_free(sm_path); %global mv_bytes_free; %let mv_bytes_free = -1; /* In case of error */ %let fi

如何检查驱动器上的剩余空间,以及是否小于1GB,以便使用SAS输出消息。
我只有一个检查SAS文件大小的代码。

我基本上已经根据您的要求修改了link中可用的代码。我还添加了一些代码来修复由于引号和pipe命令而面临的问题。基本上,您应该让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;
塔兹:

假设您在Windows平台上运行SAS,将
wmic
命令输出传输到SAS可以提供大量有关系统的信息,包括磁盘上的可用空间

WMIC-使用Windows Management Instrumentation命令行; ;


谢谢,我将测试它并让您知道:)错误:需要逗号(分隔宏参数)或右括号(结束参数列表),但找到::错误:将编译一个伪宏即使我将路径更改为c:271%macro windows_bytes_free(\\SERVER\G:),我也会用此代码获得上述错误;错误:无效的宏参数名称\。它应该是一个有效的SAS标识符,长度不超过32个字符。错误:将编译一个伪宏。我花了一些时间才弄明白,但现在代码有两行被修改,实际的
管道
命令和附加的
文件名
variableDesktop或server?什么操作系统?这取决于您的安装。您提供的信息无法回答您的问题。我想检查服务器的驱动器空间(g:)什么服务器,操作系统?。到目前为止你试过什么?有代码吗?Windows 7 64位,它是一个名为G:的网络驱动器。本页上的最后一段代码正在运行,但正在打印所有驱动器的可用空间,我只想打印G:驱动器上的可用空间,以GB而不是字节为单位。。我已经尝试了一些东西在程序打印,但它不会工作。谢谢:)最后一段代码似乎有效,我从所有可用的驱动器中都能得到结果,但我想要一个特定的驱动器G:它也是一个服务器驱动器。。
%windows_bytes_free(c:);
%let csvdata = %sysfunc(pathname(work))\wmic_output.csv;

filename wmic_csv "&csvdata" encoding="utf-16";
filename gather pipe "wmic logicaldisk get name,size,freespace /format:csv"; 

* process the wmic command and strip off blank first row and extraneous CR character at end of line;
data _null_;
  infile gather; 
  input;
  if _n_ > 1;
  _infile_ = compress(_infile_, '0d'x);
  file wmic_csv;
  put _infile_;
run;

proc import replace out=diskinfo file=wmic_csv dbms=csv;
run;

data _null_;
  set diskinfo;
  if freespace < 1e9 then put "WARNING: " name "has remaining" freespace=;
run;
* WMIC - Using Windows Management Instrumentation Command-line;
* https://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx;

%let xmldata = %sysfunc(pathname(work))\wmic_output.xml;
%let xmlautomap  = %sysfunc(pathname(work))\wmic_output-automap.xml;
%let xmlmap =  %sysfunc(pathname(work))\wmic_output-map.xml;

filename wmic "&xmldata" encoding="utf-16";
filename wmicmap "&xmlmap";

filename gather pipe "wmic logicaldisk get name,size,freespace /format:rawxml > ""&xmldata""";

data _null_;
  infile gather;
  input;
  put _infile_;
  rc = sleep(.1,1);
run;

libname wmic xmlv2 automap=replace xmlmap=wmicmap;

proc copy in=wmic out=work;
run;

proc transpose data=work.property out=properties(drop=_name_) suffix=_text;
  by instance_ordinal;
  id property_name;
  var value; 
run;

filename gather;
filename wmic;
filename wmicmap;