Chapter Contents

Previous

Next
SAS Companion for the OpenVMS Operating Environment

Reading from and Writing to OpenVMS Commands (Pipes)

Under OpenVMS, you can now 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

Use the following FILENAME statement syntax to assign filerefs to a pipe:

FILENAME fileref PIPE 'OpenVMS-command' <options>

fileref
is the name by which you reference the pipe from the SAS System.

PIPE
identifies the device type as an OpenVMS pipe.

'OpenVMS-command'
is the name of one or more OpenVMS commands to which you want to route output or from which you want to read input. The command must be enclosed in single or double quotes.

options
control how the external file is processed. See FILENAME for more information.

Note:   Only the LRECL= host external I/O option is supported with the PIPE device.  [cautionend]

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, the SAS System assumes that the input is coming from an OpenVMS command. If the fileref is used in a FILE statement, the SAS System assumes that the output is going 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.

For example, 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 file name, 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. 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;

To run the program, use the OpenVMS PIPE command to send the output of the DIR/DATE command to the SAS command:

$pipe dir/date | sas dir

The output is stored in dir.lis and the log is stored in dir.log. See Controlling Log and Output Destinations for more details about routing SAS log and procedure output.


Using the Fileref for Writing

When the fileref is used for writing, the output from the SAS System is read in by the specified OpenVMS command, which then executes.

In the following example, the OpenVMS CREATE command takes its input from the CXTFILE fileref and the file LIST.TXT is created in the default directory. The file LIST.TXT contains one record:

Mary 39 jacks

The code creates the data in a SAS program and sends the data to an external file via PIPE:

filename extfile pipe 'create list.txt';
data a;  
   input name $ num toy$;
   file cxtfile;
   put _infile_;
   cards;
Mary   39   jacks
;


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.