Don’t let your macros crash and burn

0

Your macro just crashed and burned.  So, what's the problem?  Let’s take a look:

The text OR in the code above was misinterpreted as a logical operator.  To correct this issue, use the %STR function to protect (disable the normal meaning of) special characters and mnemonics in constant text:

The macro below hasn't changed but correctly uses the %STR function, same as above.  So, what’s the problem this time?  Hint:  The parameter value has changed;  from NY (innocent) to OR (problem):

The %SUPERQ function in the code below is needed. Let’s examine why:

%SUPERQ vs %STR:

  • %STR protects constant text that you type within your macro code.
  • %SUPERQ protects the resolved value of a macro variable, during macro execution.

In the above example, the problem is not STATE.  The problem is the resolved value of STATE (OR).  Therefore, the %SUPERQ function is needed.

The argument to %SUPERQ is a single macro variable name, or an expression that resolves to a single macro variable name, without a leading ampersand (&).

%STR and %SUPERQ belong to a family of functions called quoting functions.

Don't let your macros crash and burn!  To learn more about %STR, %SUPERQ, and other quoting functions, attend our SAS Macro Language 2: Advanced Techniques course.

Share

About Author

Jim Simon

Principal Technical Training Consultant

Jim Simon is a principal instructor and course developer for SAS Education. Jim has a bachelor's degree from UCLA and a master's degree from California State University at Northridge. Prior to joining the SAS Irvine office in 1988, Jim was an instructor at Ventura College and a SAS programmer at The Medstat Group in Santa Barbara. Jim's areas of specialization include the DATA step, application development, web enablement, and the SAS macro language. A native of Southern California, Jim enjoys anything in the warm California sun. On weekends, Jim loves jumping in his Corvette, turning up the stereo, and cruising Pacific Coast Highway, top down, South to Laguna Beach or North to his old home town, Santa Barbara.

Comments are closed.

Back to Top