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;
1 | %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 following are the other 10 overrides:
P1
name of the 1st data
item name to keep.
P2
name of the 2nd data
item name to keep.
P3
name of the 3rd data
item name to keep.
P4
name of the 4th data
item name to keep.
P5
name of the 5th data
item name to keep.
P6
name of the 6th data
item name to keep.
P7
name of the 7th data
item name to keep.
P8
name of the 8th data
item name to keep.
P9
name of the 9th data
item name to keep.
P10
name of the 10th data
item name to keep.
Ten data items are allowed because there are 10 input fields in the INPUT statement
for the database.
|
2 | The DATA statement names the DATA step view as specified by the macro variable &VIEWNAME. |
3 | The KEEP statement identifies the variables that comprise the observations in the output data set. In this case, there are as many as 10. |
4 | This is the same code that was executed in the introductory example in An Introductory Example of a DATA Step Program. |
5 | %MEND defines the end of macro CUSTVIEW. |
6 | %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. |
7 | %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. |
8 | Data set Work.PhoneList is created by obtaining data using the DATA step view Work.Phone. |
9 | 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. |