|SAS/ACCESS Interface to IMS-DL/I Software|
In a DATA step, the SAS/ACCESS interface to IMS-DL/I uses special extensions of standard SAS INFILE and FILE statements to access DL/I resources. These extended statements are referred to as the DL/I INFILE and DL/I FILE statements, and their corresponding INPUT and PUT statements are referred to as DL/I INPUT and DL/I PUT statements.
DL/I INFILE and DL/I INPUT statements work together to issue DL/I get calls. The DL/I INFILE, DL/I FILE, and DL/I PUT statements work together to issue update calls.
The DL/I INFILE statement tells the SAS System where to find the parameters needed to build DL/I calls. Special DL/I INFILE statement extensions
The DL/I INFILE statement is necessary to identify the parameters for a call. However, the call is not actually formatted and issued until a DL/I INPUT statement is executed for get calls or DL/I FILE and DL/I PUT statements are executed for update calls.
The DL/I INFILE statement is required in any DATA step that accesses a DL/I database because the special extensions of the DL/I INFILE statement specify variables that set up the DL/I calls. When a DL/I INFILE statement is used with a DL/I INPUT statement, get calls are issued. When a DL/I INFILE statement is used with DL/I FILE and DL/I PUT statements, update calls are issued. Both get and update calls can be issued in one DATA step.
The syntax and use of the DL/I INFILE, DL/I FILE, DL/I INPUT, and DL/I PUT statements are described in detail later in this chapter.
|DL/I Input and Output Buffers|
Two separate buffers are allocated by the SAS System as I/O areas for data transfer. The input buffer is for DL/I segments retrieved by get calls. The output buffer is for data written by an update call. The length of each buffer is specified by the LRECL= option in the DL/I INFILE statement. The default length for each buffer is 1,000 bytes.
The input buffer is formatted by DL/I in the same way an I/O area for any DL/I program is formatted. If a fixed-length segment is retrieved, the fixed-length segment begins in column 1 of the input buffer. If a segment of varying length is retrieved, the length field (LL field) in IB2. format (half-word binary) begins in column 1 and the varying-length segment data follow immediately. If a path of segments is retrieved, the buffer contains the concatenated segments.
The format of the output buffer is like that of the input buffer. If a fixed-length segment is written, the fixed-length segment begins in column 1 of the output buffer. If a varying-length segment is written, the length field in IB2. format (half-word binary) begins in column 1. The varying-length segment data immediately follow the length field. If a path of segments is written, the buffer contains the concatenated segments.
The segment data format in the output buffer is determined by the DL/I PUT statement and must match the original segment data format. See Using the DL/I PUT Statement for more information on how to format segment data in the output buffer.
The format of the data in a segment is determined by the application program that wrote the data segment originally, just as the data format in any other record is determined by the program that writes the record. When you write an IMS-DL/I DATA step program you must know the segment's format in order to read data from the segment with a DL/I INPUT statement or to write data to the segment with a DL/I PUT statement.
In most cases, you are probably not the person who originally determined the segment data format. Segment data format information is stored in different ways at different installations. For example, the information may be obtained from a data dictionary, COBOL or Assembler copy libraries, source programs, a SAS macro library, or other documentation sources. DBA staff at your installation can help you find the segment data formats you need.
|An Introductory Example of a DATA Step Program|
The following example is a simple IMS-DL/I DATA step program that reads segments from a DL/I database and creates a SAS data set from data in the retrieved segments. Next, the program processes the SAS data set with PROC SORT and PROC PRINT.
The example accesses the ACCTDBD database with a PSB called ACCTSAM. ACCTSAM contains five PCBs; the second PCB contains a view of the ACCTDBD database in which the CUSTOMER segment is the only sensitive segment. See Appendix 2 for information on the databases, PSBs, segments, and fields used in this example and other examples in this book. This example uses the DLI option of the INFILE statement, which tells the SAS System that the INFILE statement refers to a DL/I database. Other nondefault region and execution parameters in effect include these:
Defaults for other region and execution parameters in this example include these:
If you do not want to use these defaults, the special statement and product options that you can specify for IMS-DL/I are described later in this chapter.
The numbered comments following this program correspond to the numbered statements in the program:
 data work.custlist;  infile acctsam dli status=st pcbno=2;  input @1 soc_sec_number $char11. @12 customer_name $char40. @52 addr_line_1 $char30. @82 addr_line_2 $char30. @112 city $char28. @140 state $char2. @142 country $char20. @162 zip_code $char10. @172 home_phone $char12. @184 office_phone $char12.;  if st ¬= ' ' then do; file log; put _all_; abort; end; run;  proc sort data=work.custlist; by customer_name;  options linesize=132; proc print data=work.custlist; var home_phone office_phone; id customer_name; title2 'Customer Phone List';  proc print data=work.custlist; var addr_line_1 addr_line_2 city state country zip_code; id customer_name; title2 'Customer Address List'; run;
|The DATA statement references a temporary SAS data set called CUSTLIST, which is to be opened for output.|
|The INFILE statement tells SAS to use a PSB called ACCTSAM. The DLI option tells SAS that ACCTSAM is a DL/I PSB instead of a fileref. The statement also tells the IMS-DL/I interface to use the second PCB and to return the DL/I STATUS code in the ST variable.|
|The INPUT statement causes a GN (get-next)
call to be issued. The PCB being used is sensitive only to the CUSTOMER segment,
so the get-next calls retrieve only CUSTOMER segments. When the INPUT statement
executes, data are retrieved from a CUSTOMER segment and placed in the input
buffer. The data are then moved to the specified SAS variables in the program
data vector (SOC_SEC_NUMBER, CUSTOMER_NAME, and so on).
As the DATA step executes, CUSTOMER segments are retrieved from ACCTDBD, and SAS observations that contain the CUSTOMER data are written to the CUSTLIST data set. Because program access is sequential, the DATA step stops executing when the DL/I STATUS code indicates an end-of-file condition.
|The status code is checked for non-blank
values. For any non-blank status code except
|The SORT procedure sorts the CUSTLIST data set alphabetically by customer name.|
|The PRINT procedure first prints a Customer Phone List.|
|The procedure is invoked again to print a Customer Address List.|
SAS LOG for ACCTSAM Example shows the SAS log for this example.
SAS LOG for ACCTSAM Example
12 data work.custlist; 13 infile acctsam dli status=st pcbno=2; 14 input @1 soc_sec_number $char11. 15 @12 customer_name $char40. 16 @52 addr_line_1 $char30. 17 @82 addr_line_2 $char30. 18 @112 city $char28. 19 @140 state $char2. 20 @142 country $char20. 21 @162 zip_code $char10. 22 @172 home_phone $char12. 23 @184 office_phone $char12.; 24 if st ^= ' ' then 25 do; 26 file log; 27 put _all_; 28 abort; 29 end; 30 NOTE: The infile ACCTSAM is: (system-specific pathname), (system-specific file attributes) NOTE: GB -End of database encountered NOTE: 10 records were read from the infile (system-specific pathname). The minimum record length was 225. The maximum record length was 225. NOTE: The data set WORK.CUSTLIST has 10 observations and 10 variables. 31 proc sort data=work.custlist; 32 by customer_name; 33 34 options linesize=132; NOTE: The data set WORK.CUSTLIST has 10 observations and 10 variables. 35 proc print data=work.custlist; 36 var home_phone office_phone; 37 id customer_name; 38 title2 'Customer Phone List'; 39 NOTE: The PROCEDURE PRINT printed page 1. 40 proc print data=work.custlist; 41 var addr_line_1 addr_line_2 city state country zip_code; 42 id customer_name; 43 title2 'Customer Address List'; 44 run; NOTE: The PROCEDURE PRINT printed page 2.
Customer Phone List and Customer Address List show the output of this example.
Customer Phone List
Customer Phone List customer_name home_phone office_phone BARNHARDT, PAMELA S. 803-345-4346 803-355-2543 BOOKER, APRIL M. 803-657-1346 COHEN, ABRAHAM 803-657-7435 803-645-4234 LITTLE, NANCY M. 803-657-3566 O'CONNOR, JOSEPH 803-657-5656 803-623-4257 PATTILLO, RODRIGUES 803-657-1346 803-657-1345 SMITH, JAMES MARTIN 803-657-3437 SUMMERS, MARY T. 803-657-1687 WALLS, HOOPER J. 803-657-3098 803-645-4418 WIKOWSKI, JONATHAN S. 803-467-4587 803-654-7238
Customer Address List
Customer Address List addr_ customer_name line_1 addr_line_2 city state country zip_code BARNHARDT, PAMELA S. RT 2 BOX 324 CHARLOTTESVILLE VA USA 25804-0997 BOOKER, APRIL M. 9712 WALLINGFORD PL. GORDONSVILLE VA USA 26001-0670 COHEN, ABRAHAM 2345 DUKE ST. CHARLOTTESVILLE VA USA 25804-0997 LITTLE, NANCY M. 4543 ELGIN AVE. RICHMOND VA USA 26502-3317 O'CONNOR, JOSEPH 235 MAIN ST. ORANGE VA USA 26042-1650 PATTILLO, RODRIGUES 9712 COOK RD. ORANGE VA USA 26042-1650 SMITH, JAMES MARTIN 133 TOWNSEND ST. GORDONSVILLE VA USA 26001-0670 SUMMERS, MARY T. 4322 LEON ST. GORDONSVILLE VA USA 26001-0670 WALLS, HOOPER J. 4525 CLARENDON RD RAPIDAN VA USA 22215-5600 WIKOWSKI, JONATHAN S. 4356 CAMPUS DRIVE RICHMOND VA USA 26502-5317
Top of Page
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.