Using the FILENAME PIPE Option to Run DOS Commands
Instead of using an X statement to submit operating system commands in Windows and Unix environments, consider using a FILENAME statement with the PIPE device. The approach has two advantages over using the X statement:
- In a Windows environment, there is no appearance of the DOS window.
- The output from an operating system command can be read into SAS as if it were an ordinary external file.
The syntax is: FILENAME fileref PIPE ‘operating system command’;
Use a DATA step with an INFILE statement to submit the operating system command that is specified for the given Fileref. To capture the output that results from the command’s execution, include an INPUT statement.
The following screen shot shows two examples of the FILENAME PIPE device being used. The first one creates a new directory and the second one copies files into the new target directory:
The PUT statement writes the results from each command to the log, where _INFILE_ is an automatic DATA step variable which contains the contents of the input buffer. The resulting log is as follows: