0

I have a list of directories in the form of work.Directories.data, let's say (variable is directory). Each row contains a string that looks like this:

C:\importantfolder\subfolder\

I want to find the contents of each of these directories and combine them to make a new dataset. Here is what I have so far:

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

I get some serious problems, but I think my code looks pretty harmless. What is the issue?

Joe
  • 62,789
  • 6
  • 49
  • 67
Jesse_m_m
  • 185
  • 1
  • 9
  • Possible duplicate of [Why won't my macro variable resolve?](http://stackoverflow.com/questions/27946244/why-wont-my-macro-variable-resolve) – Joe Apr 07 '17 at 22:33
  • Dratted dupehammer doesn't work when [tag:sas] isn't on the question initially. Anyway - OP - your pipe is in single quotes. – Joe Apr 07 '17 at 22:34
  • 1
    And for future reference - "get some serious problems" isn't really what we want to see, we want to see the error messages, as those would make this quite clear. Otherwise a good question. – Joe Apr 07 '17 at 22:35

1 Answers1

1

The error message seems pretty straight forward.

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 could not find any files named "&STRING".

Use double quotes around your strings if you want SAS to resolve your macro expressions.

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

Or just avoid macro completely.

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;
Tom
  • 47,574
  • 2
  • 16
  • 29