Hi, I have two questions about a the code below. I have it working fine; I am curious to understand why I need to do pieces of it the way I have it working. What the code below does is searches a set of .sas programs in a set of directories for a set of strings, and then stores the full path to the sas program that has each string anywhere in the directory tree. I realize I could be more efficient about my "find" strategy (i.e., I could combine all of the strings in one grep statement with multiple -e parameters), but I wanted individual rows for each match for subsequent processing anyway). Plus, I didn't think of that alternate strategy until I'd already written this... and it works. My questions are these: Why do I need the "stop" command after the last end? If I exclude the stop command, it becomes an infinite loop and just keeps executing on the four "rows" created by the 2x2 do loop. I suspect it has something to do with how SAS knows in general when to exit a data step, but the answer isn't obvious to me. In regular data step processing, when, for example, a set data set is being processed, SAS stops when it gets to EOF of the incoming data set(s). In this case, there are no incoming datasets, but we're creating just the four records to go through. If I use a do until (i.e., do until (eof)) instead of a do while (i.e., do while (not eof)), the program exits without error the first time it encounters an infile pipe with no matching files. Again, it works fine with the do while loop. I understand that a do until loop executes once before checking the condition, but why does executing either the input, checking _infile_ value, or output cause the overall program to exit? data ListOfFilePaths;
length topOfFileTree $50 stringsToSearchFor $15 pipecmd $150 filePath $500;
do topOfFileTree = "/firstTopLevelDirectory", "/secondTopLevelDirectory";
do stringsToSearchFor = "string1", "string2";
pipecmd="find " || strip(topOfFileTree) || " -name '*.sas' -type f -exec grep -ilF " || strip(dbname) || " {} \;";
infile dummy pipe filevar=pipecmd end=eof;
do while (not eof); *if replace this with do until (eof), then data step exits on first infile pipe with no rows;
input;
filePath=strip(_infile_);
output;
end;
end;
end;
stop; *if this isn't here, program seems to become an infinite loop. Not sure why;
run;
... View more