|Using External Files and Devices|
|What Are Pipes?|
Under OpenVMS, you can use the FILENAME statement to assign filerefs to a pipe. Pipes enable your SAS application to receive input from any OpenVMS command that writes to SYS$OUTPUT, and to write input to any OpenVMS command that reads from SYS$INPUT.
Note: The PIPE device cannot be used from an OpenVMS captive account. For more information, see Limitations of Using a Captive Account.
|Syntax for Assigning Filerefs to a Pipe|
|FILENAME fileref PIPE 'OpenVMS-command ' <options>|
control how the external file is processed. See FILENAME Statement: OpenVMS for more information.
Note: Only the LRECL= host option or the LRECL= system option for external files is supported with the PIPE device.
Whether you are using the OpenVMS command as input or output depends on whether you are using the fileref for reading or writing. For example, if the fileref is used in an INFILE statement, SAS assumes that the input is coming from the output of an OpenVMS command. If the fileref is used in a FILE statement, SAS assumes that the output is going to be the input to an OpenVMS command.
|Using the Fileref for Reading|
When the fileref is used for reading, the specified OpenVMS command executes, and any output that is sent to SYS$OUTPUT or SYS$ERROR is read through the fileref. SYS$INPUT is connected to the null device.
The following SAS program uses the PIPE device-type keyword to send the output of the DIRECTORY command to a SAS DATA step. The resulting SAS data set contains the filename, file type, version, and date and time information about each file in the default directory.
filename dir_list pipe 'directory/date'; data sasjobs; infile dir_list pad; length fname $ 80; input fname $ char80.; run; proc print data=sasjobs; run;
The DIRECTORY/DATE command retrieves information about the files in the current directory. The FILENAME statement connects the output of the DIRECTORY command to the fileref DIR_LIST. The DATA step creates a data set named SASJOBS from the INFILE statement; SASJOBS points to the input source. The INPUT statement reads the first 80 characters in each input line.
In the following example, the SYS$INPUT fileref is used to read input through a pipe into the SAS command. Assume that the SAS command executes the SAS program. The program in the previous example has been changed and stored in the file DIR.SAS. By placing the piping operation outside the SAS program, you can change the information that is passed to the program through the command without having to modify the program itself.
data sasjobs infile SYS$INPUT; length fname $ 80; input fname $ char80.; run; proc print data=sasjobs; run;
The output is stored in DIR.LIS and the log is stored in DIR.LOG. See Overriding the Default Log and Output Destinations under OpenVMS for more details about routing SAS log and procedure output.
|Using the Fileref for Writing|
filename extfile pipe 'create list.txt'; data a; input name $ num toy$; file extfile; put _infile_; cards; Mary 39 jacks ;