BookmarkSubscribeRSS Feed

%LET macro statement

Started ‎07-06-2018 by
Modified ‎07-06-2018 by
Views 8,199

The %LET macro statement or %LET statement is a SAS macro language statement that assigns text to a macro variable.

 

Syntax

%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.

Usage

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 preceded 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.

 

Further reading

Introductory papers on the Macro Language

SAS Documentation

  • SAS Macro Language: Reference: %LET Statement - Versions: 9.2, 9.3, 9.4

This article was originally published by Cameron on sasCommunity.org.

Version history
Last update:
‎07-06-2018 03:40 PM
Updated by:
Contributors

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags