![]() Chapter Contents |
![]() Previous |
![]() Next |
| SAS Companion for the OS/2 Environment |
The named pipes capability is one of the most powerful tools available in the SAS System under OS/2 for communicating with other applications. The named pipes feature enables bidirectional data or message exchange between applications that are on the same machine or applications that are on separate machines across a network. Communication Using Named Pipes illustrates these two basic methods of communication.
Communication Using Named Pipes
| Named Pipe Syntax |
| FILENAME fileref NAMEPIPE 'pipe-specification' <named-pipe-options>; |
You can use the following arguments with this form of the FILENAME statement:
This argument has two mutually exclusive forms:
There are two values for the seconds argument that indicate special cases:
All of these options are consistent with terminology used in OS/2 programmers' reference guides.
| Using the CALL RECONNECT Routine |
There is a special SAS CALL routine that works with named pipes. The CALL RECONNECT routine enables the server to disconnect the current client and try to connect to the next available client. Normally, the pipe is terminated when the client side of the pipe sends an end-of-file character to the server. To break the pipe connection at any time, the server SAS session can issue a CALL RECONNECT statement. For an example of this routine, see The CALL RECONNECT Routine.
| Using Named Pipes in SCL |
| If the server accesses the pipe as... | then the client must access the pipe as... |
|---|---|
| I (input) | O (output) |
| O (output) | S (sequential) |
| U (update) | O (output) or S (sequential) |
| Named Pipe Examples |
The simplest named pipe configuration is one server connected to one client, as shown in One Server Connected to One Client.
One Server Connected to One Client
In the first SAS session, create a named pipe as a server:
/* Creates a pipe called WOMEN, acting */
/* as a server. The server waits 30 */
/* seconds for a client to connect. */
filename women namepipe '\\.\pipe\women'
server retry=30;
/* This code writes three records into */
/* the named pipe called WOMEN. */
data class;
input name $ sex $ age;
file women;
if upcase(sex)='F' then
put name age;
cards;
MOORE M 15
JOHNSON F 16
DALY F 14
ROBERTS M 14
PARKER F 13
;
/* Creates a pipe called WOMEN, acting */
/* as a client. The client waits 30 */
/* seconds for a server to connect. */
filename in namepipe '\\.\pipe\women' client
retry=30;
data female;
infile in;
input name $ age;
proc print;
run;
filename results namepipe '\\.\pipe\results'
server retry=60;
proc printto print=results new;
run;
proc summary data=monthly;
run;
You can choose to have one server connected to several clients. In this case, the named pipe configuration looks like that shown in One Server Connected to Several Clients.
One Server Connected to Several Clients
In the first SAS session, submit the following statements:
/* Creates a pipe called SALES, acting */
/* as a server. The server waits 30 */
/* seconds for a client to connect. */
/* After the client has disconnected, */
/* this server SAS session tries to */
/* connect to the next available client */
filename daily namepipe '\\.\pipe\sales'
server eofconnect retry=30;
/* This program reads in the daily */
/* sales figures sent from each client.*/
data totsales;
infile daily;
input dept $ item $ total;
run;
In the second SAS session, submit the following statements:
/* Creates a pipe called SALES, acting */
/* as a client. The client waits forever */
/* for a server to connect. After the */
/* first client has disconnected, the */
/* second client connects with the server.*/
/* The first client is the TOYS dept. */
filename dept1 namepipe '\\.\pipe\sales'
client retry=-1;
data toys;
input item $ total;
dept='TOYS';
file dept1;
put dept item total;
cards;
DOLLS 100
MARBLES 10
BLOCKS 50
GAMES 60
CARS 40
;
/* The second client is the SPORTS dept.*/
/* These data could come from a separate */
/* SAS session. */
filename dept2 namepipe '\\.\pipe\sales'
client retry=-1;
data sports;
input item $ total;
dept='SPORTS';
file dept2;
put dept item total;
cards;
BALLS 30
BATS 65
GLOVES 15
RACKETS 75
FISHING 20
TENTS 115
HELMETS 45
;
In the first SAS session, submit the following statements:
/* Defines a named pipe called LINE. */
/* Use the NOBLOCK option to specify */
/* that if no data are available when */
/* the read is performed, then continue.*/
/* Use the EOFCONNECT option to tell */
/* the server to try to connect with a */
/* new client if an end-of-file is */
/* encountered. Use the RETRY= option */
/* to tell the server to look for any */
/* new clients for 20 seconds. */
filename data namepipe '\\.\pipe\line' server
noblock eofconnect retry=20;
/* This DATA step reads in all data */
/* from any clients connected to the */
/* named pipe called LINE. */
data all;
infile data length=len;
input @;
/* If the length of the incoming */
/* record is 0, then no data were */
/* found in the pipe; otherwise, */
/* read the incoming data. */
if len ne 0 then
do;
input machine $ width weight;
output;
end;
run;
proc print;
run;
/* Defines a named pipe called LINE. */
/* The RETRY= option is set such that */
/* the clients wait forever until a */
/* server is available */
/* (that is, RETRY=-1). */
filename data namepipe '\\.\pipe\line'
client retry=-1;
/* This is information from the */
/* first machine/client. */
data machine1;
file data;
input width weight;
machine='LINE_1';
put machine width weight;
cards;
5.3 18.2
3.2 14.3
4.8 16.9
6.4 20.8
4.3 15.4
6.1 19.5
5.6 18.9
;
/* This is information from the */
/* second machine/client. */
data machine2;
file data;
input width weight;
machine='LINE_2';
put machine width weight;
cards;
4.3 17.2
5.2 18.4
6.8 19.9
3.4 14.5
5.3 18.6
4.1 17.1
6.6 19.5
;
In the server SAS session, submit the following statements:
filename data namepipe '\\.\pipe\orders'
server noblock eofconnect retry=30;
data all;
infile data length=len missover;
input @;
/* If the length of the incoming */
/* record is 0, then no data were */
/* found in the pipe; otherwise, */
/* read the incoming data */
if len ne 0 then
do;
input operator $ item $ quantity $;
if item='' or quantity='' then
delete;
else
output;
put operator= item= quantity=;
end;
/* If no data are being transmitted,*/
/* try reconnecting to the next */
/* available client. */
else
do;
/* Use the named pipe fileref */
/* as the argument of */
/* CALL RECONNECT. */
call reconnect('data');
end;
run;
In the second SAS session, which is the first data entry operator, submit the following statements:
filename data namepipe '\\.\pipe\orders'
client retry=-1;
data entry1;
if _n_=1 then
do;
window entry_1
#1 @2 'ENTER STOP WHEN YOU ARE FINISHED'
#3 @5 'ITEM NUMBER - ' item $3.
#5 @5 'QUANTITY - ' quantity $3.;
end;
do while (upcase(_cmd_) ne 'STOP');
display entry_1;
file data;
put 'ENTRY_1' +1 item quantity;
item='';
quantity='';
end;
stop;
run;
In the third SAS session, which is the second data entry operator, submit the following statements:
filename data namepipe '\\.\pipe\orders'
client retry=-1;
data entry2;
if _n_=1 then
do;
window entry_2
#1 @2 'ENTER STOP WHEN YOU ARE FINISHED'
#3 @5 'ITEM NUMBER - ' item $3.
#5 @5 'QUANTITY - ' quantity $3.;
end;
do while (upcase(_cmd_) ne 'STOP');
display entry_2;
file data;
put 'ENTRY_2' +1 item quantity;
item='';
quantity='';
end;
stop;
run;
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.