Search code examples
escapingsassas-macro

Macro escape string


I'm trying to print a line to the console which should print one macro variable and one piece of text with an ampersand in it. Let me illustrate this with a small example:

%LET THIS_IS_A_MACRO_VAR = test; 
%PUT &THIS_IS_A_MACRO_VAR..&THIS_SHOULD_BE_TEXT;

When running this I would like the output to be:

test.&THIS_SHOULD_BE_TEXT

Coming from languages like PHP I expected there was something like an escape character. Unfortunately I could find anything similar.

I tried using different placements of ' and " but that led to both variable being interpreted as macro variable or both variables not. Also a try using %NRQUOTE was without succes. Lastly, I tried concatenating two strings: "&THIS_IS_A_MACRO_VAR..&" || "THIS_SHOULD_BE_TEXT".

I hope someone knows how to do this.


Solution

  • A quick way is to simply separate the ampersand from the text, to prevent it being resolved as a macro variable, as follows:

    %LET THIS_IS_A_MACRO_VAR = test; 
    %PUT &THIS_IS_A_MACRO_VAR..%str(&)THIS_SHOULD_BE_TEXT;
    

    this gives:

    test.&THIS_SHOULD_BE_TEXT