<?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: Resolve Double-Nested Macro Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710626#M218791</link>
    <description>&lt;P&gt;Easy?&amp;nbsp; Maybe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=1;
%let count1 = subcount1;
%let subcount1 = 100;

test2="&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;count&amp;amp;n."; &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Jan 2021 16:54:09 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2021-01-11T16:54:09Z</dc:date>
    <item>
      <title>Resolve Double-Nested Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710620#M218786</link>
      <description>&lt;P&gt;Here's an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=1;
%let count1 = subcount1;
%let subcount1 = 100;

data test;
set mor_filelist_ma;
n="&amp;amp;n."; *Resolves to 1 as expected;
count1="&amp;amp;count1."; *resolves to subcount1 as expected;
subcount1="&amp;amp;subcount1."; *resolves to 100 as expected;
test1="&amp;amp;count&amp;amp;n."; *resolves to subcount1 as expected;
test2="&amp;amp;&amp;amp;&amp;amp;count&amp;amp;n."; *resolves to subcount1 - expecting 100;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How do I get test2 to resolve to 100 instead of subcount1? I'm thinking this is easy and I'm just missing something...&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 16:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710620#M218786</guid>
      <dc:creator>theponcer</dc:creator>
      <dc:date>2021-01-11T16:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve Double-Nested Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710624#M218789</link>
      <description>&lt;P&gt;Please post the log from the data step. I have an inkling that there's a clue in there.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 16:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710624#M218789</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-11T16:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve Double-Nested Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710626#M218791</link>
      <description>&lt;P&gt;Easy?&amp;nbsp; Maybe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=1;
%let count1 = subcount1;
%let subcount1 = 100;

test2="&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;count&amp;amp;n."; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jan 2021 16:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710626#M218791</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-01-11T16:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve Double-Nested Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710627#M218792</link>
      <description>&lt;P&gt;Indirect referencint (nothing "nested" here) can be problematic in many ways, often involving way more references than you think are needed:&lt;/P&gt;
&lt;P&gt;Consider this output:&lt;/P&gt;
&lt;PRE&gt;227  %let n=1;
228  %let count1 =subcount1;
229  %let subcount1 =100;
230
231  %let test2=&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;count&amp;amp;n.;
232
233  %put &amp;amp;test2;
100
&lt;/PRE&gt;
&lt;P&gt;2,3,4 and 5 &amp;amp; at the beginning are insufficient, 6 works on my system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which why you really want to determine if the indirect reference is really needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 16:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710627#M218792</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-11T16:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve Double-Nested Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710629#M218794</link>
      <description>&lt;P&gt;Don't do that.&amp;nbsp;&amp;nbsp;&lt;A href="https://www.amazon.com/Doctor-hurts-when-Jokes-Cartoons/dp/150043230X" target="_blank"&gt;https://www.amazon.com/Doctor-hurts-when-Jokes-Cartoons/dp/150043230X&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Since you need 3 to get value of COUNT1 then you will probably need 6 to get the value macro variable named in COUNT1.&lt;/P&gt;
&lt;PRE&gt;529   %let n=1;
530   %let count1 = subcount1;
531   %let subcount1 = 100;
532   %put &amp;amp;=n &amp;amp;=count1 &amp;amp;=subcount1 ;
N=1 COUNT1=subcount1 SUBCOUNT1=100
533   %put &amp;amp;&amp;amp;&amp;amp;count&amp;amp;n;
subcount1
534   %put &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;count&amp;amp;n;
100
&lt;/PRE&gt;
&lt;P&gt;But it is just much easier on your brain if you do the steps explicitly instead.&lt;/P&gt;
&lt;PRE&gt;535   %let var1=count&amp;amp;n;
536   %let var2=&amp;amp;&amp;amp;&amp;amp;var1;
537   %let var3=&amp;amp;&amp;amp;&amp;amp;var2;
538   %put &amp;amp;=var1 &amp;amp;=var2 &amp;amp;=var3;
VAR1=count1 VAR2=subcount1 VAR3=100
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 17:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710629#M218794</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-11T17:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve Double-Nested Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710634#M218799</link>
      <description>&lt;P&gt;How do the six ampersands work?&lt;/P&gt;
&lt;P&gt;In the first pass, double ampersands are converted to single ampersands, and single ampersands are resolved:&lt;/P&gt;
&lt;PRE&gt;&amp;amp;&amp;amp; &amp;amp;&amp;amp; &amp;amp;&amp;amp; count &amp;amp;n&lt;/PRE&gt;
&lt;P&gt;resolves to&lt;/P&gt;
&lt;PRE&gt;&amp;amp; &amp;amp; &amp;amp; count 1&lt;/PRE&gt;
&lt;P&gt;(blanks inserted to make it easier to read)&lt;/P&gt;
&lt;P&gt;In the next pass, the same happens:&lt;/P&gt;
&lt;PRE&gt;&amp;amp;&amp;amp; &amp;amp;count1&lt;/PRE&gt;
&lt;P&gt;resolves to&lt;/P&gt;
&lt;PRE&gt;&amp;amp; subcount1&lt;/PRE&gt;
&lt;P&gt;and that is resolved in the third pass to 100.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 17:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710634#M218799</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-11T17:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve Double-Nested Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710647#M218809</link>
      <description>&lt;P&gt;If you are using a data step anyway you can make it easier by using SYMGET() and SYMGETN() functions instead of trying to use macro code to resolve the references.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;599   %let n=1;
600   %let count1 = subcount1;
601   %let subcount1 = 100;
602
603   data test;
604     length name1 name2 $32 value 8 ;
605     name1=cats('count',symgetn('n'));
606     name2=symget(name1);
607     value=symgetn(name2);
608     put (_all_) (=);
609   run;

name1=count1 name2=subcount1 value=100
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jan 2021 17:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-Double-Nested-Macro-Variables/m-p/710647#M218809</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-11T17:58:45Z</dc:date>
    </item>
  </channel>
</rss>

