1

I have email list in storage, which I include so that country specific people get notifications. But for demonstration purposes let use one:

I want to dynamically select address depending on variable &system:

%let SEList1 = "my.email@domain.eu";

%put system.list1.;
/*system.list1, which is ok*/
%put &system.list1.;
/*SElist1, which is ok*/
%put &&system.list1.;
/*SElist1, Hmm? Shouldn't this be "my.email@domain.eu"*/


%put &&&system.list1.;
/*"my.email@domain.eu", umm... ok? */
/*Lets keep going.... */

%put &&&&system.list1.;
/*SElist1. wut?  */
%put &&&&&system.list1.;
/*"my.email@domain.eu"*/
%put &&&&&&system.list1.;
/*"my.email@domain.eu"*/
%put &&&&&&&system.list1.;
/*&"my.email@domain.eu"*/
%put &&&&&&&&system.list1.;
/*SElist1. You got to be kidding me?*/

Question:

a)Why does not the && not resolve to address, but &&& does?

b)What on Earth is happening with levels of &*4+

Joe
  • 62,789
  • 6
  • 49
  • 67
pinegulf
  • 1,334
  • 13
  • 32

1 Answers1

5

When the SAS macro processor sees two ampersands && it resolves that to one & and sets a flag that indicates it needs to reprocess the string for more macro variable resolutions.

So &&&system.list1. gets processed as && , &system. and list1. which gives you an intermediate value of &SElist1.. So on the second pass you get the value of your indirect macro variable reference.

178 %let SEList1 = "my.email@domain.eu";
179 %let system = SE ;
180 options symbolgen ;
181 %put &&&system.list1.;
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable SYSTEM resolves to SE
SYMBOLGEN: Macro variable SELIST1 resolves to "my.email@domain.eu" "my.email@domain.eu"

If you only had two && then the intermediate value is just &system.list1. which will split into &system. and list1. so the result should be SElist1.

You can add as many as you want and follow this rule. For example if you had 6 then after the first pass it would be the same as if you had started with 3 since each pair just gets reduced to one. So using 6 yields the same result as using 3 but it just needs an extra pass at resolving the string.

Tom
  • 47,574
  • 2
  • 16
  • 29
  • 1
    Hmm. The logic seems to be right. Does it make sense? Well, that's up for debate I quess. Thanks anyways. – pinegulf Mar 23 '17 at 19:25