使用宏命令搜索数据集中的多个目录

时间:2017-04-07 20:57:49

标签: sas sas-macro

我有一个work.Directories.data形式的目录列表,让我们说(变量是目录)。每行包含一个如下所示的字符串:

C:\ importantfolder \的子文件夹\

我想找到每个目录的内容并将它们组合起来制作一个新的数据集。以下是我到目前为止的情况:

setStaticGlobalPath

我遇到了一些严重的问题,但我认为我的代码看起来非常无害。有什么问题?

1 个答案:

答案 0 :(得分:1)

错误信息似乎非常简单。

1    data test ;
2      infile 'dir "&STRING" /s /b' pipe truncover;
3      input dirlist $char1000.;
4    run;

NOTE: The infile 'dir "&STRING" /s /b' is:
      Unnamed Pipe Access Device,
      PROCESS=dir "&STRING" /s /b,RECFM=V,
      LRECL=32767

Stderr output:
File Not Found
NOTE: 0 records were read from the infile 'dir "&STRING" /s /b'.
NOTE: The data set WORK.TEST has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.99 seconds
      cpu time            0.04 seconds

Windows无法找到任何名为"&STRING"的文件。

如果您希望SAS解析您的宏表达式,请在字符串周围使用双引号。

"dir ""$STRING"" /s /b"

或者完全避免使用宏。

data BigList;
  set Directories;
  length cmd $500 ;
  cmd = catx(' ','dir',quote(trim(directory)),'/s /b');
  infile cmd pipe filevar=cmd truncover end=eof;
  do while (not eof);
    input dirlist $char1000.;
    output;
  end;
run;