<?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: %let macro and %eval do I need double ampersand or something else? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864454#M341387</link>
    <description>Thank you, this is what I was looking for.</description>
    <pubDate>Thu, 16 Mar 2023 01:41:46 GMT</pubDate>
    <dc:creator>DougHold</dc:creator>
    <dc:date>2023-03-16T01:41:46Z</dc:date>
    <item>
      <title>%let macro and %eval do I need double ampersand or something else?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864447#M341382</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CPI2017 = 110; 
%let Y = 2020;

Data _null_;
%put CPI in 2017 is &amp;amp;CPI2017;
%put CPI in %eval(&amp;amp;Y-3) is &amp;amp;CPI%eval(&amp;amp;Y-3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why does the second put statement not produce the same result as the first one (I get a warning)? I thought maybe I need double ampersand, like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put CPI in %eval(&amp;amp;Y-3) is &amp;amp;&amp;amp;CPI%eval(&amp;amp;Y-3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But that also doesn't work, I still only get "CPI in 2017 is &amp;amp;CPI2017".&lt;/P&gt;
&lt;P&gt;What I want is "CPI in 2017 is 110", just like the first statement.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 00:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864447#M341382</guid>
      <dc:creator>DougHold</dc:creator>
      <dc:date>2023-03-16T00:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: %let macro and %eval do I need double ampersand or something else?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864449#M341383</link>
      <description>&lt;P&gt;I think the %eval is leaving SAS looking for a simple &amp;amp;cpi variable, which you don't have.&lt;/P&gt;
&lt;P&gt;If you remove the %eval this way&lt;/P&gt;
&lt;PRE&gt;%let t=%eval(&amp;amp;Y-3);
%put CPI in %eval(&amp;amp;Y-3) is &amp;amp;&amp;amp;CPI&amp;amp;t;
&lt;/PRE&gt;
&lt;P&gt;Yields&lt;/P&gt;
&lt;P&gt;CPI in 2017 is 110&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 00:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864449#M341383</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-16T00:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: %let macro and %eval do I need double ampersand or something else?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864450#M341384</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Double (or triple) ampersands can't help you here.&amp;nbsp; I often think they will, but they can't help you build a macro token when part of the token comes from executing a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to get what you want is to use %unquote().&amp;nbsp; Unquote can also be used to 'glue' text together to make a single token, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    %let CPI2017 = 110;
2    %let Y = 2020;
3
4    %put CPI in 2017 is &amp;amp;CPI2017;
CPI in 2017 is 110
5    %put CPI in %eval(&amp;amp;Y-3) is %unquote(%nrstr(&amp;amp;CPI)%eval(&amp;amp;Y-3));
CPI in 2017 is 110
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So %nrstr() is used above to mask the &amp;amp;, then %eval() executes, then %unquote unmasks the &amp;amp; and &amp;amp;CPI2017 resolves.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 01:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864450#M341384</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-16T01:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: %let macro and %eval do I need double ampersand or something else?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864453#M341386</link>
      <description>Good suggestion, thanks that works too.</description>
      <pubDate>Thu, 16 Mar 2023 01:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864453#M341386</guid>
      <dc:creator>DougHold</dc:creator>
      <dc:date>2023-03-16T01:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: %let macro and %eval do I need double ampersand or something else?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864454#M341387</link>
      <description>Thank you, this is what I was looking for.</description>
      <pubDate>Thu, 16 Mar 2023 01:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864454#M341387</guid>
      <dc:creator>DougHold</dc:creator>
      <dc:date>2023-03-16T01:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: %let macro and %eval do I need double ampersand or something else?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864455#M341388</link>
      <description>&lt;P&gt;Don't do that. Macro language is complex enough, it not worth trying overcomplicate things just to save a line of code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the %EVAL() to generate a new variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either one with the NAME of the macro variable you want.&lt;/P&gt;
&lt;P&gt;Or one with the YEAR value you want.&lt;/P&gt;
&lt;PRE&gt;1031  %let name=CPI%eval(&amp;amp;y-3);
1032  %put CPI in %eval(&amp;amp;Y-3) is &amp;amp;&amp;amp;&amp;amp;name;
CPI in 2017 is 110
1033  %let year=%eval(&amp;amp;y-3);
1034  %put CPI in %eval(&amp;amp;Y-3) is &amp;amp;&amp;amp;CPI&amp;amp;year;
CPI in 2017 is 110
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 03:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/let-macro-and-eval-do-I-need-double-ampersand-or-something-else/m-p/864455#M341388</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-16T03:45:03Z</dc:date>
    </item>
  </channel>
</rss>

