You can tell them apart because the names of macro

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: You can tell them apart because the names of macro variables start with an ampersand (&), while the names of macros start with a percent sign (%).1 A macro variable is like a standard data variable except that it does not belong to a data set and has only a single value which is always character. The value of a macro variable could be a variable name, a numeral, or any text you want substituted in your program. A macro, however, is a larger piece of a program that can contain complex logic including complete DATA and PROC steps, and macro statements such as %IF-%THEN/%ELSE and %DO-%END. Macros often --but not always --contain macro variables. 1 SUGI 29 Tutorials THINK GLOBALLY AND LOCALLY Macro variables come in two varieties: either local or global. A macro variable's scope is local if it is defined inside a macro. Its scope is global if it is defined in "open code" which is everything outside a macro. You can use a global macro variable anywhere in your program, but you can use a local macro variable only inside its own macro. If you keep this in mind as you write your programs, you will avoid two common mistakes: trying to use a local macro variable outside its own macro, and accidentally creating local and global macro variables having the same name. YOU MAY QUOTE ME ON THAT Another caveat to keep in mind is that the macro processor doesn't check for macros inside single quotes. To get around this, simply use double quotes for titles or other quoted strings that contain macro code. SUBSTITUTING TEXT WITH %LET %LET is a straightforward macro statement that simply assigns a value to a macro variable. Despite its simplicity, by learning this one statement you will greatly increase the flexibility of your programs. Suppose you have a program that you run once a month. Every time you have to edit the program so it will select data for the correct month and print the correct title. This is time-consuming and prone to errors. You can use %LET to create a macro v...
View Full Document

Ask a homework question - tutors are online