As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.
Here are some tips for How to share your SAS knowledge with your professional network.
%LET macro statement
- This is a work in progress. You can contribute to this article.
- %LET identifier = text ;
- identifier is the name of any valid SAS macro variable.
- text is the text to be assigned to the macro variable. The text can include macro variables, macro quoting functions and escaped characters. However, leading and trailing blank spaces surrounding the text are ignored.
The %LET macro statement can be used in open code. It is often used at the beginning of a program to provide parameter values or settings for the code that follows. This avoids needing to hard code values in other parts of a program and makes a program more maintainable.
If some or all of the text is contained in another macro variable then that macro variable name needs to be preceeded by an ampersand symbol (&). Also, that macro variable name needs to be followed by a period (.) if there is no trailing space or other character that identifies the starts of a new token. This is so the macro language parser can tell where the macro variable name ends, so it will not misinterpret trailing text as part of the macro variable name.
Various quoting and unquoting macro functions can also be used to hide characters from the parser, so they can be assigned as as text.
%LET statements are useful for setting constant text values that can be substituted in one or more places in subsequent code. They can assist in making code more reusable.
- Changing Data Set Variables into Macro Variables
- Quick Hits - My Favorite SAS® Tricks
- Macro Quoting to the Rescue: Passing Special Characters
- Quotes within Quotes: When Single (‘) and Double (“) Quotes are not Enough
- Passing Real Numbers as Macro Variables
- Passing Values
- Resolving a macro variable within single quotes
- Tips:Setting Default Values for Macro Parameters
Introductory papers on the Macro Language
- Five Ways to Create Macro Variables: A Short Introduction to the Macro Language
- Before You Get Started: A Macro Language Preview in Three Parts