Chapter Contents |
Previous |
Next |
SAS/ACCESS Interface to IMS-DL/I Software |
A DATA step view is a stored, named DATA step program that you can specify in other SAS procedures to access IMS-DL/I data directly. A view's input data can come from one or more sources, including external files and other SAS data sets.
The following DATA step code is contained in a macro that is invoked twice to create two distinct DATA step views. When the DATA step views are executed, CUSTOMER segments are read from the ACCTDBD DL/I database and selected data values are placed in two SAS data sets. Then each SAS data set is processed with PROC SORT and PROC PRINT to produce the same outputs as the introductory example in An Introductory Example of a DATA Step Program.
The numbered comments following this program correspond to the numbered statements in the program:
[1] %macro custview(viewname=,p1=,p2=,p3=,p4=,p5=, p6=,p7=,p8=,p9=,p10=); [2] data &viewname / view=&viewname; [3] keep &p1 &p2 &p3 &p4 &p5 &p6 &p7 &p8 &p9 &p10; [4] 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; [5] %mend; [6] %custview(viewname=work.phone, p1=customer_name, p2=home_phone, p3=office_phone); [7] %custview(viewname=work.address, p1=customer_name, p2=addr_line_1, p3=addr_line_2, p4=city, p5=state, p6=country, p7=zip_code); options linesize=132; [8] data work.phonlist; set work.phone; run; [9] proc sort data=work.phonlist; by customer_name; run; proc print data=work.phonlist; title2 'Customer Phone List'; run; [10] data work.addrlist; set work.address; run; [11] proc sort data=work.addrlist; by customer_name; run; proc print data=work.addrlist; title2 'Customer Address List'; run;
%MACRO defines the start of the macro
CUSTVIEW which allows 11 input overrides. VIEWNAME is the name of the DATA
step view to be created. The other 10 overrides are:
Ten data items are allowed because there are 10 input fields in the INPUT statement for the database. | |||||||||||||||||||||
The DATA statement names the DATA step view as specified by the macro variable &VIEWNAME. | |||||||||||||||||||||
The KEEP statement identifies the variables that will comprise the observations in the output data set. In this case, there will be as many as 10. | |||||||||||||||||||||
This is the same code that was executed in the introductory example in An Introductory Example of a DATA Step Program. | |||||||||||||||||||||
%MEND defines the end of macro CUSTVIEW. | |||||||||||||||||||||
%CUSTVIEW generates a DATA step view named WORK.PHONE, which when executed produces observations containing the data items CUSTOMER_NAME, HOME_PHONE, and OFFICE_PHONE. | |||||||||||||||||||||
%CUSTVIEW generates a DATA step view named WORK.ADDRESS, which when executed produces observations containing the data items CUSTOMER_NAME, ADDR_LINE_1, ADDR_LINE_2, CITY, STATE, COUNTRY, and ZIP_CODE. | |||||||||||||||||||||
Data set WORK.PHONLIST is created by obtaining data using the DATA step view WORK.PHONE. | |||||||||||||||||||||
PROC SORT sorts WORK.PHONLIST and PROC PRINT prints it out. | |||||||||||||||||||||
[10] | Data set WORK.ADDRLIST is created by obtaining data using the DATA step view WORK.ADDRESS. | ||||||||||||||||||||
[11] | PROC SORT sorts WORK.ADDRLIST and PROC PRINT prints it out. |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.