<?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: infinite looping in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293246#M60977</link>
    <description>&lt;P&gt;What if a DATA step could do this, but without using DO UNTIL or first. or last.?&amp;nbsp; Would that be acceptable?&lt;BR /&gt;&lt;BR /&gt;Actually, the hardest part is deciding on the rules.&amp;nbsp; That part is up to you.&amp;nbsp; For example, if your incoming data set contains 183 observations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Which groups should contain 18 observations and which should contain 19 observations?&lt;/LI&gt;
&lt;LI&gt;If observations 15 through 25 contain the same actual value, should they be split up into separate groups or kept in the same group?&amp;nbsp; If they are kept in the same group, do they belong in group 1 or group 2 (or doesn't it matter)?&amp;nbsp; Extending that idea, what if 50 observations all have the same value?&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Mon, 22 Aug 2016 20:00:18 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-08-22T20:00:18Z</dc:date>
    <item>
      <title>infinite looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293188#M60948</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to execute the folloing code but its going for the infinite looping. Can anyone help me to understand why its happening.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;input Account Transaction;&lt;BR /&gt;cumm=0;&lt;BR /&gt;do until (mod(_n_,2)=0);&lt;BR /&gt;cumm + Transaction;&lt;BR /&gt;end;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0&lt;BR /&gt;0 1&lt;BR /&gt;1 1&lt;BR /&gt;0 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;~Rahul&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 17:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293188#M60948</guid>
      <dc:creator>Rahul_SAS</dc:creator>
      <dc:date>2016-08-22T17:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: infinite looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293190#M60950</link>
      <description>&lt;P&gt;On your first observation, _n_=1.&amp;nbsp; So mod(_n_, 2) is also 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is nothing inside your loop that changes the value of _n_.&amp;nbsp; That's where you are creating your infinite loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is worth noting that _n_ is not the observation number (although it often matches the observation number in many DATA steps).&amp;nbsp; It is actually a counter, counting the number of times that the programming logic has left the DATA statement in order to execute the remaining statements within the DATA step.&amp;nbsp; Understanding _n_ requires a solid understanding of how DATA steps work.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 17:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293190#M60950</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-22T17:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: infinite looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293193#M60953</link>
      <description>&lt;P&gt;_n_ does not change in your do until() loop. So if the until condition isn't met after the first run, it is never met.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What did you intend to do?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 17:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293193#M60953</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-08-22T17:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: infinite looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293219#M60966</link>
      <description>so what about the further iterations i.e. _n_=1,2,3...</description>
      <pubDate>Mon, 22 Aug 2016 18:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293219#M60966</guid>
      <dc:creator>Rahul_SAS</dc:creator>
      <dc:date>2016-08-22T18:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: infinite looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293229#M60970</link>
      <description>&lt;P&gt;There are no further iterations.&amp;nbsp; Your program begins an infinite loop on the first iteration when _n_=1.&amp;nbsp; There is no way of getting to a further iteration.&amp;nbsp; Most likely, you would accomplish your task using this variation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;input Account Transaction;&lt;BR /&gt;if mod(_n_,2)=0 then cumm + Transaction;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0&lt;BR /&gt;0 1&lt;BR /&gt;1 1&lt;BR /&gt;0 0&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not 100% clear that this would be the right "solution", but it is consistent with your original program.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 19:17:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293229#M60970</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-22T19:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: infinite looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293230#M60971</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2837"&gt;@Rahul_SAS&lt;/a&gt; wrote:&lt;BR /&gt;so what about the further iterations i.e. _n_=1,2,3...&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What about them? In your original code you never leave _n_ =1. So you never the second read from the input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you attempting to accomplish with that code?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 19:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293230#M60971</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-22T19:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: infinite looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293238#M60974</link>
      <description>hi pgstate,&lt;BR /&gt;could you please explain it...why _n_ does not change do untill() loop.&lt;BR /&gt;&lt;BR /&gt;See, let me explain my prblem again...&lt;BR /&gt;I have 100 obs n two variables Actual and predict. I have to group them in 10 groups each and take sum.of each of 10 groups will make an output dataset with 10 observation which are grouped n summed.&lt;BR /&gt;as we can achieve using..&lt;BR /&gt;Proc Rank data=DSN groups=10;&lt;BR /&gt;Var Actual;&lt;BR /&gt;run;&lt;BR /&gt;and then can get the cumulative sum using first. n last.&lt;BR /&gt;And I want to replace proc rank with Do Until() loop.</description>
      <pubDate>Mon, 22 Aug 2016 19:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293238#M60974</guid>
      <dc:creator>Rahul_SAS</dc:creator>
      <dc:date>2016-08-22T19:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: infinite looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293242#M60975</link>
      <description>&lt;P&gt;You do not want a do until because it isn't going to read new values. If you want to accumulate then maybe something more like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   input Account Transaction;

   cumm + Transaction;
   if mod(_n_,2) = 0 then do;
      output;
      cumm=0;
   end;

datalines;
1 0
0 1
1 1
0 0
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW example data of 0 and 1 for this is pretty marginal as there are likley lots of ways to get a result that is correct for mod(2) but wouldn't work for more actual values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 19:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293242#M60975</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-22T19:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: infinite looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293246#M60977</link>
      <description>&lt;P&gt;What if a DATA step could do this, but without using DO UNTIL or first. or last.?&amp;nbsp; Would that be acceptable?&lt;BR /&gt;&lt;BR /&gt;Actually, the hardest part is deciding on the rules.&amp;nbsp; That part is up to you.&amp;nbsp; For example, if your incoming data set contains 183 observations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Which groups should contain 18 observations and which should contain 19 observations?&lt;/LI&gt;
&lt;LI&gt;If observations 15 through 25 contain the same actual value, should they be split up into separate groups or kept in the same group?&amp;nbsp; If they are kept in the same group, do they belong in group 1 or group 2 (or doesn't it matter)?&amp;nbsp; Extending that idea, what if 50 observations all have the same value?&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 22 Aug 2016 20:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infinite-looping/m-p/293246#M60977</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-22T20:00:18Z</dc:date>
    </item>
  </channel>
</rss>

