mac1c05 - 1 Chapter 5: Macro Programs 5.1 Conditional...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Chapter 5: Macro Programs 5.1 Conditional Processing 5.2 Parameter Validation 5.3 Iterative Processing 5.4 Global and Local Symbol Tables 2 Chapter 5: Macro Programs 5.1 Conditional Processing 5.1 Conditional Processing 5.2 Parameter Validation 5.3 Iterative Processing 5.4 Global and Local Symbol Tables 3 Objectives Conditionally process SAS code within a macro program. Monitor macro execution. Insert entire steps, entire statements, and partial statements into a SAS program. 3 4 Macro-Level Programming Macro-level programming can generate code conditionally. Conditions can be based on the following: system values parameter values data values Example: Orion Star submits a program every night to report daily sales. Every Friday, a second program is submitted to summarize weekly sales. Automate the application so that only one program is required. 4 5 Macro-Level Programming 5 Yes Always print the daily report proc print data=orion.order_fact; where order_date="&sysdate9"d; var product_id total_retail_price; title "Daily sales: &sysdate9"; run; proc means data=orion.order_fact n sum mean; where order_date between "&sysdate9"d - 6 and "&sysdate9"d; var quantity total_retail_price; title "Weekly sales: &sysdate9"; run; Is it Friday? 6 Conditional Processing Conditional processing is performed with %IF-%THEN and %ELSE statements. General form of %IF-%THEN and %ELSE statements: expression can be any valid macro expression. The %ELSE statement is optional. These macro language statements can be used only inside a macro definition. 6 %IF expression %THEN action ; %ELSE action ; %IF expression %THEN action ; %ELSE action ; 7 Macro Expressions Similarities to SAS expressions: arithmetic operators logical operators (Do not precede AND or OR with %.) comparison operators (symbols and mnemonics) case sensitivity special WHERE operators not valid Differences compared to SAS expressions: Character operands are not quoted. Ranges such as 1 <= &x <= 10 behave differently. The IN operator does not require parentheses. 7 8 Conditional Processing These actions can follow the keywords %THEN and %ELSE: a macro language statement a macro variable reference a macro call any text 8 9 Conditional Processing The MLOGIC system option displays macro execution messages in the SAS log, including messages about the following: macro initialization parameter values results of arithmetic and logical operations macro termination General form of the MLOGIC|NOMLOGIC option: The default setting is NOMLOGIC. 9 OPTIONS MLOGIC ; OPTIONS NOMLOGIC ; OPTIONS MLOGIC ; OPTIONS NOMLOGIC ; 10 Macro-Level Programming 10 Yes Always print the daily report proc print data=orion.order_fact; where order_date="&sysdate9"d; var product_id total_retail_price; title "Daily sales: &sysdate9"; run; proc means data=orion.order_fact n sum mean; where order_date between "&sysdate9"d - 6 and "&sysdate9"d; var quantity total_retail_price; title "Weekly sales: &sysdate9"; run; Is it Friday? 11...
View Full Document

This note was uploaded on 02/20/2012 for the course STAT 506 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 132

mac1c05 - 1 Chapter 5: Macro Programs 5.1 Conditional...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online