1 data work.org_department; retain iseq; 2 infile empss01 idms func=func1 record=recname area=iarea sequence=iseq errstat=err set=iset; /* BIND the DEPARTMENT record */ 3 if_n_ = 1 then do; func1 = 'BIND'; recname = 'DEPARTMENT'; 4 input; if (err ne '0000') then go to staterr; iseq = 'FIRST'; end; /* Now get the DEPARTMENT records by issuing */ /* OBTAIN for DEPT record and test for success */ func1 = 'OBTAIN'; recname = 'DEPARTMENT'; iarea = 'ORG-DEMO-REGION'; 5 input @; 6 if (err ne '0000' and err ne '0307') then go to staterr; if err eq '0307' then do; _error_ = 0; /* No more DEPT records so STOP */ stop; end; 7 input @1 department_id 4.0 @5 department_name $char45. @50 department_head 4.0; 8 iseq = 'NEXT'; 9 return; staterr: 10 put @1 'WARNING: ' @10 func1 @17 'RETURNED ERR =' @37 err; atop; end; run; 11 proc print data=work.org_department; run;
| 1 | The DATA statement references a temporary SAS data set called Org_Department, which is opened for output. |
| 2 | The
INFILE statement tells SAS to use the EMPSS01 subschema. The IDMS
option tells SAS that EMPSS01 is a CA-IDMS subschema instead of a
fileref. This statement also tells the CA-IDMS interface to use the
named SAS variables as follows:
The CA-IDMS INFILE statement
also tells the interface to store the error status from the call
in ERR.
|
| 3 | The first time through the DATA step, all CA-IDMS records that will be accessed must be bound to CA-IDMS. To bind the DEPARTMENT record type, the program sets FUNC1 to BIND and RECNAME to DEPARTMENT. |
| 4 | The CA-IDMS INPUT statement uses the values in the SAS variables FUNC1 and RECNAME to generate the first call to CA-IDMS. In this example, the call generated is a BIND for the DEPARTMENT record. All records must be bound to CA-IDMS before any data retrieval calls are performed. A null INPUT statement is used because the BIND function does not retrieve any CA-IDMS data. |
| 5 | This
INPUT statement also uses the values in the SAS variables FUNC1 and
RECNAME, along with the values in ISEQ and IAREA to generate an OBTAIN
FIRST DEPARTMENT RECORD IN AREA ORG-DEMO-REGION call. However, no
data is moved into the program data vector because no variables are
defined in the INPUT @; statement. The call
holds the contents of the input buffer and enables the DATA step to
check the call status that is returned from CA-IDMS.
|
| 6 | The program examines the status code returned by CA-IDMS. If CA-IDMS returns 0000, then the program proceeds to the next INPUT statement. If CA-IDMS does not return 0000 or 0307, then the program branches to the error routine. |
| 7 | When this INPUT statement executes, data is moved from the input buffer into the program data vector. |
| 8 | The ISEQ value is changed to NEXT to generate an OBTAIN NEXT DEPARTMENT RECORD IN AREA ORG-DEMO-REGION. |
| 9 | For the subsequent iterations of the DATA step, the RETURN statement causes execution to return to the beginning of the DATA step. |
| 10 | For any unexpected status codes, a message is written to the SAS log and the DATA step stops. |
| 11 | The PRINT procedure prints the contents of the Work.Org-Department data set. |
1 data work.org_department;
2 infile empss01 idms func=func1 record=recname area=iarea
3 sequence=iseq errstat=err set=iset;
4
5 err = '0000';
.
.
.
37 end;
38 run;
NOTE: The infile EMPSS01 is:
Subschema=EMPSS01
NOTE: 11 records were read from the infile EMPSS01.
The minimum record length was 0.
The maximum record length was 56.
NOTE: The data set WORK.ORG_DEPARTMENT has 9 observations and 3 variables.
NOTE: The DATA statement used 0.22 CPU seconds and 2629K.
39 proc print data=work.org_department;
40 run;
NOTE: The PROCEDURE PRINT printed page 1.
The SAS System
Obs department_id department_name department_
head
1 2000 ACCOUNTING AND PAYROLL 11
2 3200 COMPUTER OPERATIONS 4
3 5300 BLUE SKIES 321
4 5100 BRAINSTORMING 15
5 1000 PERSONNEL 13
6 4000 PUBLIC RELATIONS 7
7 5200 THERMOREGULATION 349
8 3100 INTERNAL SOFTWARE 3
9 100 EXECUTIVE ADMINISTRATION 30