Chapter Contents |
Previous |
Next |
SAS Companion for the OS/2 Environment |
For unnamed pipes to work with OS/2 applications that are external to the SAS System, the application program must read data from standard input (STDIN), write output to standard output (STDOUT), and write errors to standard error (STDERR). These files have numeric file handles associated with them, as follows:
File | File Handle |
---|---|
STDIN | 0 |
STDOUT | 1 |
STDERR | 2 |
When the SAS System captures STDERR from another application, the error messages are routed by default to the SAS log. If you want to write to STDIN in another application, you can use a PUT statement in a SAS DATA step. Because the SAS System can write to STDIN and capture from STDOUT in the same application, unnamed pipes can be used to send data to an external program, as well as to capture the output and error messages of the same program. You can use redirection sequences to redirect STDIN, STDOUT, and STDERR. For more information, see Using Redirection Sequences or your OS/2 documentation.
Unnamed Pipe Syntax |
To use an unnamed pipe, issue a FILENAME statement with the following syntax:
FILENAME fileref PIPE 'program-name' option-list |
You can use the following arguments with this form of the FILENAME statement:
'stockmkt.exe -all'
Using Redirection Sequences |
filename listing pipe 'dir *.sas 2>&1';
In this example, if any errors occur in executing this command, STDERR (2) is redirected to the same file as STDOUT (1). This is an example of the SAS System's ability to capitalize on operating environment capabilities. This feature of redirecting file handles is a function of the OS/2 operating environment rather than of the SAS System.
Unnamed Pipe Example |
filename stocks pipe 'stockmkt.exe -all'; data report; infile stocks; input stock $ open close change; run; proc print; var stock open close change; sum change; title 'Stock Market Report'; run;
In this example, the PIPE device-type keyword in the FILENAME statement indicates that the fileref STOCKS is an unnamed pipe. The STOCKMKT.EXE reference is the name of the stand-alone program that generates the stock market data. The INFILE statement causes the SAS System to execute the STOCKMKT.EXE program and read the data in the pipe from it. The STOCKMKT.EXE program is executed without your being aware that it is running. Because the fileref STOCKS has already been defined as an unnamed pipe, the standard output from STOCKMKT.EXE is redirected to the SAS System and captured through the INFILE statement. The SAS program reads in the variables and uses the PRINT procedure to generate a printed report. Any error messages that are generated by STOCKMKT.EXE appear in the SAS log.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.