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.
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. |