<?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: Using a text to call a macro variable (dynamic) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-text-to-call-a-macro-variable-dynamic/m-p/734747#M228883</link>
    <description>&lt;P&gt;To reference a macro variable prefix the name with the &amp;amp; character.&amp;nbsp; In the %PUT statement you can also &amp;amp;= prefix to have it print the name and the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var1 = 5;
%let var2 = 3;
%put Value of VAR1 is &amp;amp;var1;
%put &amp;amp;=var1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A macro variable name cannot include quotes so this cannot work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;'var'&amp;amp;version;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the macro processer to reevaluate the text it generates for more macro triggers use a double &amp;amp;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var1=WANT;
%let version=1;
%put &amp;amp;&amp;amp;ver&amp;amp;version;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It will replace the double &amp;amp; with a single &amp;amp; and then make another pass over the resulting string.&lt;/P&gt;
&lt;PRE&gt;&amp;amp;&amp;amp;var&amp;amp;version --&amp;gt;  &amp;amp;var1 --&amp;gt; WANT&lt;/PRE&gt;</description>
    <pubDate>Fri, 16 Apr 2021 15:16:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-04-16T15:16:44Z</dc:date>
    <item>
      <title>Using a text to call a macro variable (dynamic)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-text-to-call-a-macro-variable-dynamic/m-p/734743#M228880</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need some help to create a dynamic variable, is something like that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let var1 = 5;&lt;/P&gt;&lt;P&gt;%let var2 = 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, i need to call the var1, but i want to make it more dynamic to help in my program i tried this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let version = 1&lt;/P&gt;&lt;P&gt;%put &amp;amp;'var'&amp;amp;version&lt;/P&gt;&lt;P&gt;-&amp;gt; ERROR&lt;/P&gt;&lt;P&gt;%put &amp;amp;var&amp;amp;version&lt;/P&gt;&lt;P&gt;-&amp;gt; ERROR 'VAR' doesn't exist&amp;nbsp;&lt;/P&gt;&lt;P&gt;to call var1, but i didn't get success, i tried to use eval too, bu no success &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 15:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-text-to-call-a-macro-variable-dynamic/m-p/734743#M228880</guid>
      <dc:creator>Thiago_Oliv</dc:creator>
      <dc:date>2021-04-16T15:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using a text to call a macro variable (dynamic)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-text-to-call-a-macro-variable-dynamic/m-p/734746#M228882</link>
      <description>&lt;P&gt;Please show what you expect for output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp; references a macro variable. &amp;amp;var1 for example. Quotes are not valid as part of a macro variable name which is the complaint from &amp;amp;'var&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;var1.&amp;amp;version;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a complicated concept called indirect referencing which may be another option&lt;/P&gt;
&lt;PRE&gt;%let var1 = 5;

%let var2 = 3;
%let version = 1;

%put &amp;amp;&amp;amp;var&amp;amp;version.;&lt;/PRE&gt;
&lt;P&gt;When multiple &amp;amp;&amp;amp; are encountered the SAS, in effect "holds" on of the &amp;amp; and resolves part of the rest so var&amp;amp;version becomes Var1 and then the &amp;amp;var1 is implemented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you don't know enough of the macro language to understand why &amp;amp;'var' was a bad idea you are very likely not ready for this as as resolving such takes a lot of practice. (and often locked up SAS sessions from bad results. Save code often.)&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 15:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-text-to-call-a-macro-variable-dynamic/m-p/734746#M228882</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-16T15:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using a text to call a macro variable (dynamic)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-text-to-call-a-macro-variable-dynamic/m-p/734747#M228883</link>
      <description>&lt;P&gt;To reference a macro variable prefix the name with the &amp;amp; character.&amp;nbsp; In the %PUT statement you can also &amp;amp;= prefix to have it print the name and the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var1 = 5;
%let var2 = 3;
%put Value of VAR1 is &amp;amp;var1;
%put &amp;amp;=var1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A macro variable name cannot include quotes so this cannot work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;'var'&amp;amp;version;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the macro processer to reevaluate the text it generates for more macro triggers use a double &amp;amp;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var1=WANT;
%let version=1;
%put &amp;amp;&amp;amp;ver&amp;amp;version;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It will replace the double &amp;amp; with a single &amp;amp; and then make another pass over the resulting string.&lt;/P&gt;
&lt;PRE&gt;&amp;amp;&amp;amp;var&amp;amp;version --&amp;gt;  &amp;amp;var1 --&amp;gt; WANT&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Apr 2021 15:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-text-to-call-a-macro-variable-dynamic/m-p/734747#M228883</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-16T15:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using a text to call a macro variable (dynamic)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-text-to-call-a-macro-variable-dynamic/m-p/734749#M228885</link>
      <description>%PUT &amp;amp;&amp;amp;&amp;amp;var&amp;amp;version;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Apr 2021 15:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-text-to-call-a-macro-variable-dynamic/m-p/734749#M228885</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-16T15:27:13Z</dc:date>
    </item>
  </channel>
</rss>

