<?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 Macro variables referncing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-referncing/m-p/58467#M12673</link>
    <description>Dear Sas users!&lt;BR /&gt;
Could you please help me with example below.&lt;BR /&gt;
&lt;BR /&gt;
%let field1=text1;&lt;BR /&gt;
%let field2=text2;&lt;BR /&gt;
%let field3=text3;&lt;BR /&gt;
&lt;BR /&gt;
How can i reference particular fieldN variable if i know its number as a variable. For example %let n=1;&lt;BR /&gt;
Referencing as &amp;amp;field&amp;amp;n is miscorrect...</description>
    <pubDate>Thu, 30 Oct 2008 16:23:15 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-10-30T16:23:15Z</dc:date>
    <item>
      <title>Macro variables referncing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-referncing/m-p/58467#M12673</link>
      <description>Dear Sas users!&lt;BR /&gt;
Could you please help me with example below.&lt;BR /&gt;
&lt;BR /&gt;
%let field1=text1;&lt;BR /&gt;
%let field2=text2;&lt;BR /&gt;
%let field3=text3;&lt;BR /&gt;
&lt;BR /&gt;
How can i reference particular fieldN variable if i know its number as a variable. For example %let n=1;&lt;BR /&gt;
Referencing as &amp;amp;field&amp;amp;n is miscorrect...</description>
      <pubDate>Thu, 30 Oct 2008 16:23:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-referncing/m-p/58467#M12673</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-30T16:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables referncing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-referncing/m-p/58468#M12674</link>
      <description>Try &amp;amp;&amp;amp;field&amp;amp;n..&lt;BR /&gt;
&lt;BR /&gt;
&amp;amp;&amp;amp; "protects" &amp;amp; against expanding (&amp;amp;&amp;amp; is converted into &amp;amp;)</description>
      <pubDate>Thu, 30 Oct 2008 16:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-referncing/m-p/58468#M12674</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-30T16:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables referncing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-referncing/m-p/58469#M12675</link>
      <description>Hey Sonny,&lt;BR /&gt;
Jaroslav is right!!!. the &amp;amp;&amp;amp; would solve your problem. &lt;BR /&gt;
&lt;BR /&gt;
example::&lt;BR /&gt;
&lt;BR /&gt;
%let fruit1=Apple;&lt;BR /&gt;
%let fruit2=Orange;&lt;BR /&gt;
%let fruit3=Banana;&lt;BR /&gt;
&lt;BR /&gt;
%let n=2;&lt;BR /&gt;
proc means data=fruits;&lt;BR /&gt;
title "Sales for fruit: &amp;amp;&amp;amp;section&amp;amp;n";&lt;BR /&gt;
where section="&amp;amp;&amp;amp;section&amp;amp;n";&lt;BR /&gt;
var saleprice;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
After macro variable resolution, the preceding program becomes:&lt;BR /&gt;
&lt;BR /&gt;
proc means data=fruits;&lt;BR /&gt;
title "Sales for fruit: Orange";&lt;BR /&gt;
where section="Orange";&lt;BR /&gt;
var saleprice;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
There are certain rules that macro processor follows to resolve macro variable references that contain multiple ampersands&lt;BR /&gt;
 &amp;gt; Macro variable references are resolved from left to right.&lt;BR /&gt;
 &amp;gt; Two ampersands (&amp;amp;&amp;amp;) resolve to one ampersand (&amp;amp;).&lt;BR /&gt;
 &amp;gt; Multiple leading ampersands cause the macro processor to rescan the reference&lt;BR /&gt;
until no more ampersands can be resolved.&lt;BR /&gt;
&lt;BR /&gt;
You can take advantage of these rules to create new macro variable&lt;BR /&gt;
references.&lt;BR /&gt;
&lt;BR /&gt;
Hope that helps &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Sat, 01 Nov 2008 12:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-referncing/m-p/58469#M12675</guid>
      <dc:creator>SushilNayak</dc:creator>
      <dc:date>2008-11-01T12:37:03Z</dc:date>
    </item>
  </channel>
</rss>

