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

searching several directories in a dataset with macro commands

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

C:\importantfolder\subfolder\

我想找到这些目录中的每一个目录的内容,并将它们组合起来制作一个新的数据集。这是我目前所拥有的:

%macro ScanDirec(STRING=);
    filename temptree pipe 'dir "&STRING" /s /b' lrecl=5000;

    data SmallList;
        infile temptree truncover;
        input dirlist $char1000.;
    run;

    data BigList;
        set BigList SmallList;
    run;
%mend ScanDirec;

data SmallList;
run;
data BigList;
run;

data _null_;
    set Directories;
    call execute('%ScanDirectories('||directory||')');
run;

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

错误信息看起来很直接。

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 0 ;
  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;