{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

mac1c03 - Chapter 3 Macro Definitions 3.1 Defining and...

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

View Full Document Right Arrow Icon
1 Chapter 3: Macro Definitions 3.1 Defining and Calling a Macro 3.2 Macro Parameters 3.3 Macro Storage (Self-Study)
Background image of page 1

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

View Full Document Right Arrow Icon
2 Chapter 3: Macro Definitions 3.1 Defining and Calling a Macro 3.1 Defining and Calling a Macro 3.2 Macro Parameters 3.3 Macro Storage (Self-Study)
Background image of page 2
3 Objectives Define and call a simple macro.
Background image of page 3

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

View Full Document Right Arrow Icon
4 Defining a Macro A macro or macro definition enables you to write macro programs. General form of a macro definition: macro-name follows SAS naming conventions. macro-text can include the following: %MACRO macro-name ; macro-text %MEND < macro-name> ; %MACRO macro-name ; macro-text %MEND < macro-name> ; any text SAS statements or steps macro variable references macro statements, expressions, or calls any combination of the above
Background image of page 4
5 Macro Compilation When a macro definition is submitted, the following occur: Macro language statements, if any, are checked for syntax errors compiled. SAS statements and other text are not checked for syntax errors not compiled. The macro is stored as a SAS catalog entry in the temporary catalog work.sasmacr by default.
Background image of page 5

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

View Full Document Right Arrow Icon
6 Macro Compilation The MCOMPILENOTE=ALL option issues a note to the SAS log after a macro definition has compiled. General form of the MCOMPILENOTE= option: The default setting is MCOMPILENOTE=NONE. OPTIONS MCOMPILENOTE= ALL|NONE ; OPTIONS MCOMPILENOTE= ALL|NONE ;
Background image of page 6
7 Macro Compilation Example: Submit a macro definition. SAS Log options mcompilenote=all; %macro time; %put The current time is %sysfunc (time(),timeampm.).; %mend time; m103d01 1 options mcompilenote=all; 2 %macro time; 3 %put The current time is %sysfunc 4 (time(),timeampm.).; 5 %mend time; NOTE: The macro TIME completed compilation without errors. 3 instructions 76 bytes.
Background image of page 7

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

View Full Document Right Arrow Icon
8 Macro Storage Example: Produce a list of compiled macros stored in the default temporary catalog work.sasmacr . proc catalog cat=work.sasmacr; contents; title "My Temporary Macros"; quit; My Temporary Macros Contents of Catalog WORK.SASMACR # Name Type Create Date Modified Date Description ---------------------------------------------------------------- 1 TIME MACRO 11JUN2004:15:55:59 11JUN2004:15:55:59 PROC CATALOG Output m103d02
Background image of page 8
9 Calling a Macro A macro call causes the macro to execute is specified by placing a percent sign before the name of the macro can be made anywhere in a program (similar to a macro variable reference) represents a macro trigger is not a statement (no semicolon required). General form of a macro call: %macro-name %macro-name
Background image of page 9

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

View Full Document Right Arrow Icon
10 Calling a Macro Example: Call the TIME macro. SAS Log %time 178 %time The current time is 2:49:39 PM. m103d01
Background image of page 10
11
Background image of page 11

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

View Full Document Right Arrow Icon
12 3.01 Poll Does the macro call below require a semicolon? %time Yes No
Background image of page 12
13 3.01 Poll – Correct Answer Does the macro call below require a semicolon? %time Yes No A macro call is not a statement. A semicolon is not required and can cause problems.
Background image of page 13

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

View Full Document Right Arrow Icon
14 Simple Macro A macro can generate SAS code.
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}