space
Previous Page | Next Page

Using the SAS/ACCESS Interface to CA-IDMS

Creating DATA Step Views

The preceding introductory DATA step example can be made into a DATA step view. A DATA step view is a SAS data set of type VIEW that contains a definition of the data rather than containing the physical data. For CA-IDMS, a DATA step view is a compiled version of statements that, when executed, access and retrieve the data from CA-IDMS.

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.

Note:    You cannot name a fileref for a task that has the same name as the CA-IDMS subschema.  [cautionend]

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.

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;

[1] %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 overrides might not be specified, but one must be specified to avoid a warning message.

P1

name of the first data item name to keep.

P2

name of the second data item name to keep.

P3

name of the third data item name to keep.

Three data items are allowed because there are 3 input fields in the CA-IDMS INPUT statement for the database.

[2] The DATA statement specifies the DATA step view name.

[3] The KEEP statement identifies the variables that are available to any task that references this input DATA step view.

[4] %MEND defines the end of macro DEPTVIEW.

[5] %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.

[6] %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.

[7] Data set WORK.DEPTLIST is created using the DATA step view WORK.DEPTNAME as input.

[8] PROC PRINT prints WORK.DEPTLIST.

[9] Data set WORK.HEADLIST is created using the DATA step view WORK.DEPTHEAD as input.

[10] PROC PRINT prints WORK.HEADLIST.

space
Previous Page | Next Page | Top of Page