<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to resolve 3 macro variables at time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594272#M170701</link>
    <description>&lt;P&gt;When every there are two &amp;amp;'s next to each other they resolve to one &amp;amp; and tell the macro processor to rescan the resulting string.&lt;/P&gt;
&lt;P&gt;You can see a lot about what is happening by turn on the SYMBOLGEN option (only while debugging, if you leave it on for production runs you can get extremely large and unreadable SAS logs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;&amp;amp;Asia&amp;amp;I;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first pass will resolve the &amp;amp;&amp;amp; and &amp;amp;I and end up with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;Asia1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But for&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;&amp;amp;Asia&amp;amp;I&amp;amp;y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first pass will resolve &amp;amp;y also so you end up with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;Asia12&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you did not define a macro variable with that name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get India as the result you could write :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;&amp;amp;bulli&amp;amp;y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So to generate India you could replace BULLI in that with &amp;amp;&amp;amp;ASIA&amp;amp;I, but you need this newly inserted value to be calculated before the &amp;amp;&amp;amp; and the &amp;amp;y.&amp;nbsp; So you need to double up&amp;nbsp; the existing &amp;amp;'s so that on the first pass they will get replaced with single &amp;amp;'s.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;Asia&amp;amp;I&amp;amp;&amp;amp;y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;29    %put &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;Asia&amp;amp;I&amp;amp;&amp;amp;y;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable I resolves to 1
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable ASIA1 resolves to bulli
SYMBOLGEN:  Macro variable Y resolves to 2
SYMBOLGEN:  Macro variable BULLI2 resolves to India
India
&lt;/PRE&gt;
&lt;P&gt;Personally I find it much easier to build up to the answer in multiple steps instead of trying to figure out how many &amp;amp;'s are needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let step1=&amp;amp;&amp;amp;ASIA&amp;amp;i;
%let step2=&amp;amp;step1.&amp;amp;y;
%put Country=&amp;amp;&amp;amp;&amp;amp;step2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;34    %let step1=&amp;amp;&amp;amp;ASIA&amp;amp;i;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable I resolves to 1
SYMBOLGEN:  Macro variable ASIA1 resolves to bulli
35    %put &amp;amp;=step1;
SYMBOLGEN:  Macro variable STEP1 resolves to bulli
STEP1=bulli
36    %let step2=&amp;amp;step1.&amp;amp;y;
SYMBOLGEN:  Macro variable STEP1 resolves to bulli
SYMBOLGEN:  Macro variable Y resolves to 2
37    %put &amp;amp;=step2;
SYMBOLGEN:  Macro variable STEP2 resolves to bulli2
STEP2=bulli2
38    %put Country=&amp;amp;&amp;amp;&amp;amp;step2;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable STEP2 resolves to bulli2
SYMBOLGEN:  Macro variable BULLI2 resolves to India
Country=India
&lt;/PRE&gt;
&lt;P&gt;In general if you are doing this many levels of redirection in macro logic you are probably approaching the problem the wrong way. Use SAS code to work with data and macro code to just help generate repetitive code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 05 Oct 2019 13:54:43 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-10-05T13:54:43Z</dc:date>
    <item>
      <title>How to resolve 3 macro variables at time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594266#M170695</link>
      <description>%let X=1;&lt;BR /&gt;%let y=2;&lt;BR /&gt;%let z=3;&lt;BR /&gt;%let Asia=Harish;&lt;BR /&gt;%let Asia1=bulli;&lt;BR /&gt;%let bulli2=India;&lt;BR /&gt;%let india3=Bharat;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;&amp;amp;Asia&amp;amp;I;------- it gives bulli&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;&amp;amp;Asia&amp;amp;I&amp;amp;y;----- it doesn't give India&lt;BR /&gt;&lt;BR /&gt;How resolve above macro variable &amp;amp;&amp;amp;Asia&amp;amp;I&amp;amp;y</description>
      <pubDate>Sat, 05 Oct 2019 11:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594266#M170695</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-10-05T11:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to resolve 3 macro variables at time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594268#M170697</link>
      <description>&lt;P&gt;%put &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;Asia&amp;amp;X&amp;amp;&amp;amp;y&amp;amp;&amp;amp;&amp;amp;&amp;amp;z;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are "middle" steps, each time number of "&amp;amp; group" is doubled:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
%put &amp;amp;&amp;amp;&amp;amp;&amp;amp; &amp;amp;&amp;amp;&amp;amp;&amp;amp; &amp;amp;&amp;amp; &amp;amp;&amp;amp; &amp;amp;&amp;amp;Asia &amp;amp;X &amp;amp;&amp;amp;y &amp;amp;&amp;amp;&amp;amp;&amp;amp;z;
*/

%put 1) &amp;amp;&amp;amp;Asia&amp;amp;X;

%put 2) &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;Asia&amp;amp;X&amp;amp;&amp;amp;y;

%put 3) &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;Asia&amp;amp;X&amp;amp;&amp;amp;y&amp;amp;&amp;amp;&amp;amp;&amp;amp;z;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 12:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594268#M170697</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-10-05T12:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to resolve 3 macro variables at time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594270#M170699</link>
      <description>Can you explain why we need to put that much of ampersands(&amp;amp;)</description>
      <pubDate>Sat, 05 Oct 2019 13:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594270#M170699</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-10-05T13:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to resolve 3 macro variables at time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594271#M170700</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I'm sure you know the rule of two ampersands i.e. whenever macro processor see &amp;amp;&amp;amp; it "glues" it to &amp;amp; and do rescan. In our case we have 3 levels of "inception" so we need to ensure proper number ampersands to trigger 3 rescanning.&lt;BR /&gt;&lt;BR /&gt;Let no brackets means resolution in the first scan, then let () marks first "glue-ing", [] marks the second, and {} third. The following "bracketing" is evaluated:&lt;BR /&gt;&lt;BR /&gt;/*&lt;BR /&gt;%put {[(&amp;amp;&amp;amp;)(&amp;amp;&amp;amp;)] [(&amp;amp;&amp;amp;)(&amp;amp;&amp;amp;)]} [(&amp;amp;&amp;amp;) (&amp;amp;&amp;amp;)] (&amp;amp;&amp;amp;)Asia &amp;amp;X (&amp;amp;&amp;amp;)y [(&amp;amp;&amp;amp;)(&amp;amp;&amp;amp;)]z;&lt;BR /&gt;*/&lt;BR /&gt;&lt;BR /&gt;All the best&lt;BR /&gt;Bart&lt;BR /&gt;&lt;BR /&gt;P.S. if you need me to add some extra clarifications you will have to wait few hours until I get to my laptop, since I'm using mobile to write this replay and it's very hard ;-D ;-D</description>
      <pubDate>Sat, 05 Oct 2019 13:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594271#M170700</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-10-05T13:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to resolve 3 macro variables at time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594272#M170701</link>
      <description>&lt;P&gt;When every there are two &amp;amp;'s next to each other they resolve to one &amp;amp; and tell the macro processor to rescan the resulting string.&lt;/P&gt;
&lt;P&gt;You can see a lot about what is happening by turn on the SYMBOLGEN option (only while debugging, if you leave it on for production runs you can get extremely large and unreadable SAS logs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;&amp;amp;Asia&amp;amp;I;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first pass will resolve the &amp;amp;&amp;amp; and &amp;amp;I and end up with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;Asia1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But for&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;&amp;amp;Asia&amp;amp;I&amp;amp;y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first pass will resolve &amp;amp;y also so you end up with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;Asia12&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you did not define a macro variable with that name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get India as the result you could write :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;&amp;amp;bulli&amp;amp;y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So to generate India you could replace BULLI in that with &amp;amp;&amp;amp;ASIA&amp;amp;I, but you need this newly inserted value to be calculated before the &amp;amp;&amp;amp; and the &amp;amp;y.&amp;nbsp; So you need to double up&amp;nbsp; the existing &amp;amp;'s so that on the first pass they will get replaced with single &amp;amp;'s.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;Asia&amp;amp;I&amp;amp;&amp;amp;y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;29    %put &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;Asia&amp;amp;I&amp;amp;&amp;amp;y;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable I resolves to 1
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable ASIA1 resolves to bulli
SYMBOLGEN:  Macro variable Y resolves to 2
SYMBOLGEN:  Macro variable BULLI2 resolves to India
India
&lt;/PRE&gt;
&lt;P&gt;Personally I find it much easier to build up to the answer in multiple steps instead of trying to figure out how many &amp;amp;'s are needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let step1=&amp;amp;&amp;amp;ASIA&amp;amp;i;
%let step2=&amp;amp;step1.&amp;amp;y;
%put Country=&amp;amp;&amp;amp;&amp;amp;step2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;34    %let step1=&amp;amp;&amp;amp;ASIA&amp;amp;i;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable I resolves to 1
SYMBOLGEN:  Macro variable ASIA1 resolves to bulli
35    %put &amp;amp;=step1;
SYMBOLGEN:  Macro variable STEP1 resolves to bulli
STEP1=bulli
36    %let step2=&amp;amp;step1.&amp;amp;y;
SYMBOLGEN:  Macro variable STEP1 resolves to bulli
SYMBOLGEN:  Macro variable Y resolves to 2
37    %put &amp;amp;=step2;
SYMBOLGEN:  Macro variable STEP2 resolves to bulli2
STEP2=bulli2
38    %put Country=&amp;amp;&amp;amp;&amp;amp;step2;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable STEP2 resolves to bulli2
SYMBOLGEN:  Macro variable BULLI2 resolves to India
Country=India
&lt;/PRE&gt;
&lt;P&gt;In general if you are doing this many levels of redirection in macro logic you are probably approaching the problem the wrong way. Use SAS code to work with data and macro code to just help generate repetitive code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 13:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594272#M170701</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-05T13:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to resolve 3 macro variables at time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594278#M170704</link>
      <description>&lt;P&gt;I'm assuming you don't want to refer to &amp;amp;i at all, since you have no such macro variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other than that, I'm assuming that if you were to use &amp;amp;x instead of &amp;amp;i, you are asking the right question that you would like answered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get &amp;amp;&amp;amp;Asia&amp;amp;x&amp;amp;y to resolve to India, some modification is necessary.&amp;nbsp; But it could be with a little less effort:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let X=1;
%let y=2;
%let z=3;
%let Asia=Harish;
%let Asia1=bulli;
%let bulli2=India;
%let india3=Bharat;

%put &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;Asia&amp;amp;x..&amp;amp;y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To understand why, you need to know four rules for resolving a complex macro expression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&amp;amp;&amp;amp; resolves to &amp;amp;&lt;/LI&gt;
&lt;LI&gt;A dot can be used to delimit the name of a macro variable.&amp;nbsp; So &amp;amp;x and &amp;amp;x. both refer to the macro variable X.&lt;/LI&gt;
&lt;LI&gt;SAS resolves each piece of the expression from left to right&lt;/LI&gt;
&lt;LI&gt;If the resolution generates more macro language (such &amp;amp;&amp;amp; generating &amp;amp;), macro language re-resolves the entire expression.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;From left to right, the pieces within &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;Asia&amp;amp;x..&amp;amp;y are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;&amp;amp; ==&amp;gt; &amp;amp;&lt;BR /&gt;&amp;amp;&amp;amp; ==&amp;gt; &amp;amp;&lt;/P&gt;
&lt;P&gt;&amp;amp;&amp;amp; ==&amp;gt; &amp;amp;&lt;/P&gt;
&lt;P&gt;Asia ==&amp;gt; Asia&lt;/P&gt;
&lt;P&gt;&amp;amp;x. ==&amp;gt; 1&lt;/P&gt;
&lt;P&gt;. ==&amp;gt; .&lt;/P&gt;
&lt;P&gt;&amp;amp;y ==&amp;gt; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means the entire expression resolves to &amp;amp;&amp;amp;&amp;amp;Asia1.2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since that expression contains three ampersands, it gets resolved again.&amp;nbsp; The pieces are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;&amp;amp; ==&amp;gt; &amp;amp;&lt;/P&gt;
&lt;P&gt;&amp;amp;Asia1. ==&amp;gt; billi&lt;/P&gt;
&lt;P&gt;2 ==&amp;gt; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means the expression now becomes &amp;amp;billi2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gets resolved to India.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 17:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-resolve-3-macro-variables-at-time/m-p/594278#M170704</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-05T17:30:52Z</dc:date>
    </item>
  </channel>
</rss>

