<?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: Double Ampersand in %LET in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532004#M145727</link>
    <description>&lt;P&gt;Thanks for nice explanation. I will keep these in my mind.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Feb 2019 14:18:51 GMT</pubDate>
    <dc:creator>thepushkarsingh</dc:creator>
    <dc:date>2019-02-01T14:18:51Z</dc:date>
    <item>
      <title>Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531960#M145706</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am trying to generate X_1 = A_1; X_2 = A_1 A_2; ...X_5 = A_1 A_2 A_3 A_4 A_5; and following code does the job&lt;/P&gt;&lt;P&gt;%macro temp;&lt;BR /&gt;%let x_1 = A_1;&lt;BR /&gt;%do i= 2 %to 5;&lt;BR /&gt;%let x_&amp;amp;i. = &amp;amp;&amp;amp;x_%eval(&amp;amp;i.-1). %str( A_&amp;amp;i.);&lt;BR /&gt;%put &amp;amp;&amp;amp;x_&amp;amp;i.;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%temp;&lt;/P&gt;&lt;P&gt;The issue is on every iteration it's trying to resolve &amp;amp;X_ as well and thus throwing a warning!&lt;/P&gt;&lt;P&gt;What am I doing wrong and how can I rectify it?&lt;/P&gt;&lt;P&gt;Thanks a lot in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 13:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531960#M145706</guid>
      <dc:creator>thepushkarsingh</dc:creator>
      <dc:date>2019-02-01T13:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531965#M145710</link>
      <description>&lt;P&gt;This works for me&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro temp;
%let x_1 = A_1;
%do i= 2 %to 5;
    %let i_minus_1=%eval(&amp;amp;i-1);
    %let x_&amp;amp;i = &amp;amp;&amp;amp;x_&amp;amp;i_minus_1 A_&amp;amp;i;
    %put &amp;amp;&amp;amp;x_&amp;amp;i;
    %end;
%mend;
%temp&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Feb 2019 13:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531965#M145710</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-01T13:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531967#M145711</link>
      <description>&lt;P&gt;Why don't you do it in a data step with call symputx, where the logic is much easier to build?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length string $100;
string = "";
do i = 1 to 5;
  string = catx(' ',string,'A_' !! left(put(i,best.)));
  call symputx('X_' !! left(put(i,best.)),string);
  put string=;
end;
run;

%put x_3=&amp;amp;x_3.;
%put x_5=&amp;amp;x_5.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the data step is SAS' primary tool for handling data; the macro language is for creating dynamic code, &lt;STRONG&gt;NOT&lt;/STRONG&gt; for handling data.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 13:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531967#M145711</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-01T13:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531979#M145715</link>
      <description>&lt;P&gt;ohh, so using %eval in same expression was giving warning?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 13:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531979#M145715</guid>
      <dc:creator>thepushkarsingh</dc:creator>
      <dc:date>2019-02-01T13:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531980#M145716</link>
      <description>5, is not fixed depending on data it's changing and I am using that part inside a macro, but in first place I always thought that using macro facility is more efficient. I just want to use this as passing variable names, do you think data step will be more efficient?</description>
      <pubDate>Fri, 01 Feb 2019 13:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531980#M145716</guid>
      <dc:creator>thepushkarsingh</dc:creator>
      <dc:date>2019-02-01T13:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531983#M145717</link>
      <description>&lt;P&gt;the warnings were not the only issue in the code.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Assuming the symbol X was misspelled as x_.&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the invoked macro "TEMP".&lt;BR /&gt;1 data want; do i= 2 to 5; x_&amp;amp;i. = compress(&amp;amp;&amp;amp;x_%eval(&amp;amp;i.-1). A_&amp;amp;i.);&lt;BR /&gt;--&lt;BR /&gt;14&lt;BR /&gt;1 ! );&lt;BR /&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference X_ not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The&lt;BR /&gt;condition was: &amp;amp;i.-1&lt;BR /&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;WARNING 14-169: Assuming the symbol X was misspelled as x_.&lt;/P&gt;
&lt;P&gt;ERROR: The macro TEMP will stop executing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 13:55:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531983#M145717</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-02-01T13:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531991#M145718</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194934"&gt;@thepushkarsingh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;5, is not fixed depending on data it's changing and I am using that part inside a macro, but in first place I always thought that using macro facility is more efficient. I just want to use this as passing variable names, do you think data step will be more efficient?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You code will be clearly if you use SAS code.&amp;nbsp; Only resort to using macro logic when normal SAS code cannot do the job.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you need to reference 5 variables then just use a variable list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;result=mean(of A1-A5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So to make that dynamic you could replace just the 5 with a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=5;
....
result=mean(of A1-A&amp;amp;n);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But even if did need to generate your list of macro variables if you have a macro that is generating code already. say a data step or a proc step, then using a data step to generate macro variables will probably make it easier to create your code. It is much easier to debug a data step than a macro.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531991#M145718</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-01T14:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531993#M145719</link>
      <description>&lt;P&gt;Good question!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that you're trying to use &amp;amp;&amp;amp; to create an indirect macro reference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x_&amp;amp;i. = &amp;amp;&amp;amp;x_%eval(&amp;amp;i.-1). %str( A_&amp;amp;i.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This indirect reference works for when you have multiple &amp;amp; in a reference, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x_&amp;amp;i = &amp;amp;&amp;amp;x_&amp;amp;j;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But in your case you are generating the second part of your macro variable name with %eval.&amp;nbsp; When the macro processor (word scanner? tokenizer?) starts resolving &amp;amp;&amp;amp;x_%eval(&amp;amp;i.-1) it first sees the &amp;amp;&amp;amp; and resolves it to &amp;amp;.&amp;nbsp; Then it sees x_.&amp;nbsp; Then it sees the % and thinks it hit the end of macro variable reference because it doesn't know %eval can generate part of the macro variable name.&amp;nbsp; It knows there is still an &amp;amp; left in the token from the first pass, so it makes a second pass and tries to resolve &amp;amp;x_.&amp;nbsp; It can't resolve.&amp;nbsp; If you add %put _local_; to your macro, you will see you end up with the following macro variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;TEMP I 6
TEMP X_1 A_1
TEMP X_2 &amp;amp;x_1. &amp;#1; A_2&amp;#2;
TEMP X_3 &amp;amp;x_2. &amp;#1; A_3&amp;#2;
TEMP X_4 &amp;amp;x_3. &amp;#1; A_4&amp;#2;
TEMP X_5 &amp;amp;x_4. &amp;#1; A_5&amp;#2;
&lt;/PRE&gt;
&lt;P&gt;While the %PUT statement resolves everything like you hoped, you haven't actually built the macro variables you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;solved this nicely by refactoring to move the %eval out of the macro reference, avoiding the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One option when you want to build a macro reference from macro statements is to use quoting functions to delay the resolution of the macro variables.&amp;nbsp; It gets a little ugly (but hey, it's macro : )&amp;nbsp; but you basically quote the &amp;amp; and then %unquote it after the %eval has done its work.&amp;nbsp; Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro temp();
  %let x_1 = A_1;
  %do i= 2 %to 10;
    %let x_&amp;amp;i = %unquote(%nrstr(&amp;amp;x_)%eval(&amp;amp;i.-1)) A_&amp;amp;i;
    %put &amp;amp;&amp;amp;x_&amp;amp;i;
  %end;
  %put _local_ ;
%mend;
%temp()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:04:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531993#M145719</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-02-01T14:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531995#M145721</link>
      <description>&lt;P&gt;The macro loop is executed once, and the loop in the data step is executed once, so there's no difference there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doing a calculation in a macro may be more efficient when your code looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sashelp.class;
age = age * 12345 ** (-2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, if you change that to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
set sashelp.class;
age = age * %sysevalf(12345 ** (-2));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the macro preprocessor will evaluate the fixed part of the equation &lt;EM&gt;once&lt;/EM&gt; when the data step is compiled, instead of the data step doing the calculation for &lt;EM&gt;every&lt;/EM&gt; observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the bottom line is to always keep data handling and manipulation in Base SAS code, where the logic is easier to code and understand. Optimizations like the one above make sense only when there's a considerable performance gain.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/531995#M145721</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-01T14:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532000#M145724</link>
      <description>&lt;P&gt;It's a bit of a black box, where we don't understand what is happening 100%.&amp;nbsp; But these results suggest that you should be able to resolve the problem by forcing the macro processor to make an extra pass through the expression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; x_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &amp;amp;&amp;amp;&amp;amp;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;x_&lt;SPAN class="token macroname"&gt;%eval&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;).&lt;/SPAN&gt; A_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:14:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532000#M145724</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-01T14:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532003#M145726</link>
      <description>&lt;P&gt;Thank you very much, this makes a lot of things clear.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532003#M145726</guid>
      <dc:creator>thepushkarsingh</dc:creator>
      <dc:date>2019-02-01T14:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532004#M145727</link>
      <description>&lt;P&gt;Thanks for nice explanation. I will keep these in my mind.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532004#M145727</guid>
      <dc:creator>thepushkarsingh</dc:creator>
      <dc:date>2019-02-01T14:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532005#M145728</link>
      <description>&lt;P&gt;Thanks for the tips.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532005#M145728</guid>
      <dc:creator>thepushkarsingh</dc:creator>
      <dc:date>2019-02-01T14:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Double Ampersand in %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532007#M145730</link>
      <description>&lt;P&gt;Thanks for the solution.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-Ampersand-in-LET/m-p/532007#M145730</guid>
      <dc:creator>thepushkarsingh</dc:creator>
      <dc:date>2019-02-01T14:19:58Z</dc:date>
    </item>
  </channel>
</rss>

