<?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: please help with use of do loops and possibly macros! in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217554#M53532</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's actually a simpler program.&amp;nbsp; One way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain saved_average;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (value1 &amp;lt; value2 &amp;lt; value3) then saved_average = average1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; is saved_average &amp;gt; . then required_result = saved_average;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else required_result = average1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; drop saved_average;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 May 2015 15:19:26 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-05-20T15:19:26Z</dc:date>
    <item>
      <title>please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217549#M53527</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am quite new to SAS programming therefore would appreciate any input on the possible solution of the problem I have! &lt;/P&gt;&lt;P&gt;I have the following data &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;value1 value2 value3 average1 required_result&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&lt;/P&gt;&lt;P&gt;X&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Z&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; W&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- If row n has got the following trend - value1 &amp;gt; value2&amp;gt; value3, then use the first encountered average1 value for the next 4 rows;&lt;/P&gt;&lt;P&gt;- after 4 rows calculate if value1 &amp;gt; value2 &amp;gt; value3 is true. If it is true then use the next first encountered average1 value for another 4 rows;&lt;/P&gt;&lt;P&gt;- repeat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for example, in the first row value1 &amp;gt; value2&amp;gt; value3 (1 &amp;gt; 9 &amp;gt; 12) therefore we need to use average1 = 7 the next 4 rows starting from the first one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can you please advise how this can be coded in SAS?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you so much for all your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 13:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217549#M53527</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-20T13:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217550#M53528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am confused. Why &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;1 &amp;gt; 9 &amp;gt; 12&amp;nbsp;&amp;nbsp; ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input value1 value2 value3 average1 ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt; set have;&lt;/P&gt;&lt;P&gt; if mod(_n_,4)=1 then n+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt; set have;&lt;/P&gt;&lt;P&gt; by n;&lt;/P&gt;&lt;P&gt; retain flag;&lt;/P&gt;&lt;P&gt; if first.n then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; flag=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if value1 &amp;lt; value2 and value2 &amp;lt; value3 then flag=average1;&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 13:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217550#M53528</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-05-20T13:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217551#M53529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Apologies, Xia, quick typing!&lt;/P&gt;&lt;P&gt;I obviously meant value1 &amp;lt; value2 &amp;lt; value3 &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is your solution still going to be ok for this logic?&lt;/P&gt;&lt;P&gt;I will try it out and let you know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 13:55:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217551#M53529</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-20T13:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217552#M53530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you'll need something a little more flexible.&amp;nbsp; Here's a mildly similar approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (value1 &amp;lt; value2 &amp;lt; value3) and (saved_average=.) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max_recordnum = _n_ + 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; saved_average = average1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain max_recordnum saved_average;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ &amp;lt;= max_recordnum then required_result = saved_average; &lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ = max_recordnum then saved_average = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop saved_average max_recordnum;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 14:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217552#M53530</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-20T14:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217553#M53531</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Xia and all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i think I did not explain my problem quite well before, sorry!&lt;/P&gt;&lt;P&gt;I have attached now the picture of the excel file with the sample data (I have only my iPad with me therefore not able to do anything better).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ideally what I need is the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- I need to work out the required_result column using the following logic:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - for row 2 and 3 select average1 value (without using any other logic). Therefore required_result = 2 for row 2 and required_result = 3 for row 3;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - for all other rows use the following logic: if value1 &amp;lt; value2 &amp;lt; value3 then use the first encountered value of the average1 for at least 4 rows (7 in this case)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - continue using 7 after 4 rows if the following is FALSE - value1 &amp;lt; value2 &amp;lt; value3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - if after 4 rows above the following is TRUE - value1 &amp;lt; value2 &amp;lt; value3, then use next first encountered average1 value (24 in this case) for at least 4 rows and then repeat the logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you!&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/11310i471E609D16E99FA8/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="image.jpg" title="image.jpg" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 14:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217553#M53531</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-20T14:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217554#M53532</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's actually a simpler program.&amp;nbsp; One way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain saved_average;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (value1 &amp;lt; value2 &amp;lt; value3) then saved_average = average1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; is saved_average &amp;gt; . then required_result = saved_average;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else required_result = average1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; drop saved_average;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 15:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217554#M53532</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-20T15:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217555#M53533</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot for trying, Astounding!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;however, in my example I have numbers instead of "." - I just did not want to write it all up, now I have and attachend a new file to explain.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Green area - first two rows should always have required_result = average1 (without any other logic involved);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Orange area, that's where we start comparing value1&amp;lt; value2 &amp;lt; value3 and if it is true, we need to use the first encountered average1 and use it for the next 4 rows regardless whether condition (value1&amp;lt; value2 &amp;lt; value3) is true or not (That's why it is 7 for all 4 rows).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- White area - we continue to use previous average1 value if condition (value1&amp;lt; value2 &amp;lt; value3) is FALSE (that's why it is 7 for rows 8, 9, 10).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Blue area - if condition (value1&amp;lt; value2 &amp;lt; value3) is true then choose the first encountered average1 and use it for the next 4 rows regardless whether condition (value1&amp;lt; value2 &amp;lt; value3) is true or not (that's why it is 24 for the next 4 rows.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- White area - we continue to use previous average1 value if condition (value1 &amp;lt; value2 &amp;lt; value3) is false (that's why it's 24 for another row. i have ended file here however I have a lot more entries down as well).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope it makes sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you!&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/11284i219BE4C6535FD0C9/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="image.jpg" title="image.jpg" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 15:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217555#M53533</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-20T15:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217556#M53534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seems to make sense ... I'll go back to a variation of the first program:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (value1 &amp;lt; value2 &amp;lt; value3) and (_n_ &amp;gt; 2) and (_n_ &amp;gt; max_recordnum) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max_recordnum = _n_ + 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; saved_average = average1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain max_recordnum saved_average;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if saved_average = . then required_result = average1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else required_result = saved_average;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop saved_average max_recordnum;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 16:15:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217556#M53534</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-20T16:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217557#M53535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you so much, you are a genius, Astounding! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's great for what I explained so far, however what if we had additional condition:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- In addition to what we had before, we also have another condition to check&amp;nbsp; (value1 &amp;lt; required_result and value2 &amp;lt; required_result and value3 &amp;lt; required result). If that's true or previous condition&amp;nbsp; &lt;SPAN style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; background-color: #ffffff;"&gt; (value1 &amp;lt; value2 &amp;lt; value3&lt;/SPAN&gt;) is true then required result takes the value of the first encountered average1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a result, you can see that the RED block has got now the required_result = 5 repeated for 4 rows and then White block immediately after is still using Required_result = 5 as both of our conditions do not hold true here (value1 &amp;lt; required_result and value2 &amp;lt; required_result and value3 &amp;lt; required result) is FALSE and &lt;SPAN style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; background-color: #ffffff;"&gt; (value1 &amp;lt; value 2 &amp;lt; value3&lt;/SPAN&gt;) is also FALSE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The challenge here is that 2nd condition is using the newly created variable required_result.&lt;/P&gt;&lt;P&gt;It would be great if you can help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10888i2040209AB791A1FD/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="image.jpg" title="image.jpg" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 17:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217557#M53535</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-20T17:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217558#M53536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Red,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure how much more time I can devote, but let's start at least.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why does line 15 remain as is, instead of beginning a new set of 4 with required_result=6?&amp;nbsp; It appears that the conditions are in place:&amp;nbsp; value1 &amp;lt; 24 and value2 &amp;lt; 24 and value3 &amp;lt; 24.&lt;/P&gt;&lt;P&gt;I don't see it.&amp;nbsp; Why does line 16 should trigger a new block of 4, but line 15 does not?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 18:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217558#M53536</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-20T18:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217559#M53537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your time, Astounding, I really appreciate it!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am sorry, I made a silly error typing numbers in on my iPad - in line 15 it should be 27 instead of 7 (please see updated numbers attached).&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;therefore both conditions do not hold for line 15.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would be so grateful if you can help here!&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/11050iFCC8594254CF0ECF/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="image.jpg" title="image.jpg" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 18:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217559#M53537</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-20T18:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217560#M53538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to develop on Astounding's code and make sure that I will include the comparison with the newly extended average, however it does not work the way it should be.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can you please advise what needs to be done so that condition (&lt;SPAN style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;value1 &amp;lt; saved_average and value2 &amp;lt; saved_average and value3 &amp;lt; saved_average) always tests against not saved_average but the newly created required_result variable?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Set have;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;If (value1 &amp;lt; value2 &amp;lt; value3) and (_n_ &amp;gt; 2) and (_n_ &amp;gt; max_recordnum) then do;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;max_recordnum = _n_ + 3;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Saved_average = average1;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;End;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Retain max_recordnum saved_average;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;If saved_average = . Then required_result = average1;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Else required_result = saved_average;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;If (value1 &amp;lt; saved_average and value2 &amp;lt; saved_average and value3 &amp;lt; saved_average) and (_n_ &amp;gt; max_recordnums) and (_n_ &amp;gt; max_recordnum) then do;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;DIV&gt;max_recordnums = _n_ + 3;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Saved_average2 = average1;&lt;/P&gt;&lt;/DIV&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;End;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Retain max_recordnums saved_average2;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;If saved_average2 = .&amp;nbsp; And&amp;nbsp; saved_average = . Then required_result = average1;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Else required_result = saved_average;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;If saved_average2 &amp;lt;&amp;gt; .&amp;nbsp; Then required_result = saved_average2;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2015 11:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217560#M53538</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-21T11:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217561#M53539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Red,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the statement from the original that determines whether to begin another block of 4 records:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; if (value1 &amp;lt; value2 &amp;lt; value3) and (_n_ &amp;gt; 2) and (_n_ &amp;gt; max_recordnum) then do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems you would just need to add another condition and alter just this one statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; if ( (value1 &amp;lt; value2 &amp;lt; value3) or (value1 &amp;lt; required_result and value2 &amp;lt; required_result and value3 &amp;lt; required_result) )&lt;/P&gt;&lt;P&gt;and (_n_ &amp;gt; 2) and (_n_ &amp;gt; max_recordnum) then do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does that seem about right to you?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2015 12:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217561#M53539</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-21T12:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217562#M53540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Astounding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;yes, I have already tried and the additional condition does not work.&lt;/P&gt;&lt;P&gt;The code results stay unchanged as if there was not any additional condition.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2015 12:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217562#M53540</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-21T12:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217563#M53541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you sure you used OR in the right spot:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if ( (value1 &amp;lt; value2 &amp;lt; value3) &lt;STRONG&gt;or&lt;/STRONG&gt; (value1 &amp;lt; required_result and value2 &amp;lt; required_result and value3 &amp;lt; required_result) )&lt;/P&gt;&lt;P&gt;and (_n_ &amp;gt; 2) and (_n_ &amp;gt; max_recordnum) then do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It might help if you showed the exact code you tested.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2015 12:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217563#M53541</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-21T12:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217564#M53542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Certainly:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Set have;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;If ((value1 &amp;lt; value2 &amp;lt; value3) or (value1 &amp;lt; required_result and value2 &amp;lt; required_result and value3 &amp;lt; required_result)) and (_n_ &amp;gt; 2) and (_n_ &amp;gt; max_recordnum) then do;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;max_recordnum = _n_ + 3;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Saved_average = average1;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;End;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Retain max_recordnum saved_average;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;If saved_average = . Then required_result = average1;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Else required_result = saved_average;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;Run;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 17px; text-decoration: -webkit-letterpress;"&gt;IS the problem here because required_result is used in the first if condition before even it has been creared? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2015 12:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217564#M53542</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-21T12:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217565#M53543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, it's looking a little clearer.&amp;nbsp; The OR condition should look at SAVED_AVERAGE, rather than REQUIRED_RESULT.&amp;nbsp; SAVED_AVERAGE is retained, but REQUIRED_RESULT begins each observation as missing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: UICTFontTextStyleBody; font-size: 17px;"&gt;If ((value1 &amp;lt; value2 &amp;lt; value3) or (value1 &amp;lt; saved_average and value2 &amp;lt; saved_average and value3 &amp;lt; saved_average)) and (_n_ &amp;gt; 2) and (_n_ &amp;gt; max_recordnum) then do;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2015 12:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217565#M53543</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-21T12:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: please help with use of do loops and possibly macros!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217566#M53544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; Thank you very much, Astounding!&lt;/P&gt;&lt;P&gt;all works now as it is supposed to! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2015 14:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/please-help-with-use-of-do-loops-and-possibly-macros/m-p/217566#M53544</guid>
      <dc:creator>Red_Squirrel</dc:creator>
      <dc:date>2015-05-21T14:08:09Z</dc:date>
    </item>
  </channel>
</rss>

