Chapter Contents |
Previous |
Next |
SAS/ACCESS Interface to CA-IDMS Software: Reference |
A DATA step view is a stored SAS file that you can reference in other SAS tasks to access data directly. A view's input data can come from one or more sources, including external files and other SAS data sets. Because a DATA step view only reads (opens for input) other files, you cannot update the view's underlying data. For a complete description of using DATA step views, refer to SAS Language Reference: Dictionary.
The following DATA step code is part of a SAS macro that is invoked twice to create two DATA step views. When the DATA step views are referenced in the SET statements of the subsequent DATA step executions, DEPARTMENT records are read from the CA-IDMS database and selected record data values are placed in two SAS data sets. Then, each SAS data set is processed with PROC PRINT to produce the same output as shown in Department List.
The numbers in the program correspond to the numbered comments following the program.
[1] %macro deptview(viewname=,p1=,p2=,p3=); [2] data &viewname / view &viewname; [3] keep &p1 &p2 &p3; retain iseq; infile empss01 idms func=func1 record=recname area=iarea sequence=iseq errstat=err set=iset; /* BIND the DEPARTMENT record */ if _n_ eq 1 then do; func1 = 'BIND'; recname = 'DEPARTMENT'; input; iseq = 'FIRST'; end; /* Now get the DEPARTMENT records */ func1 = 'OBTAIN'; recname = 'DEPARTMENT'; iarea = 'ORG-DEMO-REGION'; input @; 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; input @1 department_id 4.0 @5 department_name $char45. @50 department_head 4.0; iseq = 'NEXT'; return; staterr: put @1 'WARNING: ' @10 func1 @17 'RETURNED ERR = '@37 err; stop; [4] %mend; [5] %deptview(viewname=work.deptname , p1=DEPARTMENT_ID, p2=DEPARTMENT_NAME); [6] %deptview(viewname=work.depthead , p1=DEPARTMENT_ID, p2=DEPARTMENT_HEAD); options linesize=132; [7] data work.deptlist; set work.deptname; [8] proc print data=work.deptlist; title2 'DEPARTMENT NAME LIST'; [9] data work.headlist; set work.depthead; [10] proc print data=work.headlist; title2 'HEADS OF DEPARTMENTS LIST'; run;
%MACRO defines the start of the macro
DEPTVIEW, which contains 4 parameter variables: one required and three input
overrides. VIEWNAME is required; it is the name of the DATA step view. VIEWNAME
can be overridden at macro invocation. The overrides are P1, P2, and P3. These
may or may not be specified, but one must be specified to avoid a warning
message.
Three data items are allowed because there are 3 input fields in the CA-IDMS INPUT statement for the database. | |||||||
The DATA statement specifies the DATA step view name. | |||||||
The KEEP statement identifies the variables that are available to any task that references this input DATA step view. | |||||||
%MEND defines the end of macro DEPTVIEW. | |||||||
%DEPTVIEW invokes the macro and generates a DATA step view named WORK.DEPTNAME that, when referenced as input, supplies observations containing values for the variables DEPARTMENT_ID and DEPARTMENT_NAME. | |||||||
%DEPTVIEW invokes the macro and generates a DATA step view named WORK.DEPTHEAD that, when referenced as input, supplies observations containing values for the variables DEPARTMENT_ID and DEPARTMENT_HEAD. | |||||||
Data set WORK.DEPTLIST is created using the DATA step view WORK.DEPTNAME as input. | |||||||
PROC PRINT prints WORK.DEPTLIST. | |||||||
Data set WORK.HEADLIST is created using the DATA step view WORK.DEPTHEAD as input. | |||||||
[10] | PROC PRINT prints WORK.HEADLIST. |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.