<?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: How do I used a %do loop to make this code more efficient? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-used-a-do-loop-to-make-this-code-more-efficient/m-p/797506#M313533</link>
    <description>&lt;P&gt;To indirectly address macro variables, use a double ampersand:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;&amp;amp;TopCrop&amp;amp;i.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the first round of resolving, the two ampersands are reduced to one, and the macro variable i is resolved, so it is now&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;TopCrop1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(if &amp;amp;i was 1)&lt;/P&gt;
&lt;P&gt;In the second round, &amp;amp;topcrop1 is resolved as usual.&lt;/P&gt;</description>
    <pubDate>Sun, 20 Feb 2022 21:42:48 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-02-20T21:42:48Z</dc:date>
    <item>
      <title>How do I used a %do loop to make this code more efficient?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-used-a-do-loop-to-make-this-code-more-efficient/m-p/797503#M313530</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;I'm trying to use a %do loop to replicate what the commented out code below does which is to simply set up some counters for 5 crops. The commented code works perfectly, but how do I achieve the same more efficiently using a %DO?&lt;BR /&gt;I tried using &lt;FONT color="#0000FF"&gt;&amp;amp;TopCrop&amp;amp;i.._Farm &lt;FONT color="#000000"&gt;but that doesn't work either, what am I doing wrong? Thanks for helping.&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;if Second_Level_Validation eq "Pass" or Main_Farm_Commodity in ("&amp;amp;TopCrop1.","&amp;amp;TopCrop2.","&amp;amp;TopCrop3.","&amp;amp;TopCrop4.","&amp;amp;TopCrop5.")  then 
	    do;
          &lt;FONT color="#0000FF"&gt;%do i = 1 %to 5;
	      if Main_Farm_Commodity eq "&amp;amp;TopCrop&amp;amp;i." then &amp;amp;TopCrop&amp;amp;i._Farm = 1; 
              else &amp;amp;TopCrop&amp;amp;i._Farm = 0;
          %end;&lt;/FONT&gt;
		  /*
          if Main_Farm_Commodity eq "&amp;amp;TopCrop1." then &amp;amp;TopCrop1._Farm = 1; 
          else &amp;amp;TopCrop1._Farm = 0;
		  if Main_Farm_Commodity eq "&amp;amp;TopCrop2." then &amp;amp;TopCrop2._Farm = 1; 
          else &amp;amp;TopCrop2._Farm = 0;
		  if Main_Farm_Commodity eq "&amp;amp;TopCrop3." then &amp;amp;TopCrop3._Farm = 1; 
          else &amp;amp;TopCrop3._Farm = 0;
		  if Main_Farm_Commodity eq "&amp;amp;TopCrop4." then &amp;amp;TopCrop4._Farm = 1; 
          else &amp;amp;TopCrop4._Farm = 0;
		  if Main_Farm_Commodity eq "&amp;amp;TopCrop5." then &amp;amp;TopCrop5._Farm = 1; 
          else &amp;amp;TopCrop5._Farm = 0;
		*/
		end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Feb 2022 21:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-used-a-do-loop-to-make-this-code-more-efficient/m-p/797503#M313530</guid>
      <dc:creator>baroche64</dc:creator>
      <dc:date>2022-02-20T21:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used a %do loop to make this code more efficient?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-used-a-do-loop-to-make-this-code-more-efficient/m-p/797506#M313533</link>
      <description>&lt;P&gt;To indirectly address macro variables, use a double ampersand:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;&amp;amp;TopCrop&amp;amp;i.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the first round of resolving, the two ampersands are reduced to one, and the macro variable i is resolved, so it is now&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;TopCrop1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(if &amp;amp;i was 1)&lt;/P&gt;
&lt;P&gt;In the second round, &amp;amp;topcrop1 is resolved as usual.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Feb 2022 21:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-used-a-do-loop-to-make-this-code-more-efficient/m-p/797506#M313533</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-20T21:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used a %do loop to make this code more efficient?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-used-a-do-loop-to-make-this-code-more-efficient/m-p/797508#M313535</link>
      <description>Thanks Kurt that worked! using the double ampersand and two dots:&lt;BR /&gt;&lt;BR /&gt;%do i = 1 %to 5;&lt;BR /&gt;if Main_Farm_Commodity eq "&amp;amp;&amp;amp;TopCrop&amp;amp;i.." then &amp;amp;&amp;amp;TopCrop&amp;amp;i.._Farm = 1;&lt;BR /&gt;else &amp;amp;&amp;amp;TopCrop&amp;amp;i.._Farm = 0;&lt;BR /&gt;%end;</description>
      <pubDate>Sun, 20 Feb 2022 22:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-used-a-do-loop-to-make-this-code-more-efficient/m-p/797508#M313535</guid>
      <dc:creator>baroche64</dc:creator>
      <dc:date>2022-02-20T22:09:35Z</dc:date>
    </item>
  </channel>
</rss>

