<?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: DO-LOOP Index - Why is Index not the last value specified but number greater? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514107#M138615</link>
    <description>&lt;P&gt;An iterative do loop is in fact a do while:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;set index to start value&lt;/LI&gt;
&lt;LI&gt;if index greater end value, leave&lt;/LI&gt;
&lt;LI&gt;execute loop code&lt;/LI&gt;
&lt;LI&gt;increment index&lt;/LI&gt;
&lt;LI&gt;go to 2.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;So the loop will only end when the index has gone&amp;nbsp;&lt;EM&gt;past&lt;/EM&gt; the end value.&lt;/P&gt;</description>
    <pubDate>Sat, 17 Nov 2018 06:11:02 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-11-17T06:11:02Z</dc:date>
    <item>
      <title>DO-LOOP Index - Why is Index not the last value specified but number greater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514097#M138607</link>
      <description>&lt;P&gt;Still trying to learn SAS and came across an interesting question/sample of code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the sample question/code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WORK.LOOP;&lt;BR /&gt;X = 0;&lt;BR /&gt;do Index = 1 to 5 by 3;&lt;BR /&gt;X = Index;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I can see that the final output is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X=4 Index=7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that the Index starts at 1, then increments by 3 and so forth. So technically the index output should be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Index=1&lt;/P&gt;&lt;P&gt;Index=4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is where things get muddy for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If Index = 4, and the next value is greater then 5 I would have thought the final output would be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X=4 Index=4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why would this not be the final output?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this makes sense, been quite a long day reading through stuff&lt;/P&gt;</description>
      <pubDate>Sat, 17 Nov 2018 04:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514097#M138607</guid>
      <dc:creator>rodneyc8063</dc:creator>
      <dc:date>2018-11-17T04:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: DO-LOOP Index - Why is Index not the last value specified but number greater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514098#M138608</link>
      <description>&lt;P&gt;It increments and then tests.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Nov 2018 04:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514098#M138608</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-17T04:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: DO-LOOP Index - Why is Index not the last value specified but number greater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514107#M138615</link>
      <description>&lt;P&gt;An iterative do loop is in fact a do while:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;set index to start value&lt;/LI&gt;
&lt;LI&gt;if index greater end value, leave&lt;/LI&gt;
&lt;LI&gt;execute loop code&lt;/LI&gt;
&lt;LI&gt;increment index&lt;/LI&gt;
&lt;LI&gt;go to 2.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;So the loop will only end when the index has gone&amp;nbsp;&lt;EM&gt;past&lt;/EM&gt; the end value.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Nov 2018 06:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514107#M138615</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-17T06:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: DO-LOOP Index - Why is Index not the last value specified but number greater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514121#M138624</link>
      <description>&lt;P&gt;because of the by 3 statement. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;change the by 3 to by 2 and it may make since to you.&amp;nbsp; Put a debugger into the datastep maybe like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.LOOP / debug;
X = 0;
do Index = 1 to 5 by 3;
X = Index;
end;
run;


then try this

data WORK.LOOP / debug;
X = 0;
do Index = 1 to 5 by 2;
X = Index;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Nov 2018 13:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514121#M138624</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-17T13:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: DO-LOOP Index - Why is Index not the last value specified but number greater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514129#M138626</link>
      <description>&lt;P&gt;While&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;gave you the details, here is a simplified way of looking at it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does INDEX go from 1 to 5?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the END statement, SAS adds 3 to the value of INDEX.&amp;nbsp; Then it evaluates, "Are we done yet?"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since 1 + 3 = 4 is less than 5 (the upper range of the loop), the loop executes a second time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once again, at the END statement, SAS adds 3 to the value of INDEX.&amp;nbsp; Then it evalutes, "Are we done yet?"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since 4 + 3 = 7 is greater than 5 (the upper range of the loop), the loop is now over (with INDEX equal to 7).&lt;/P&gt;</description>
      <pubDate>Sat, 17 Nov 2018 15:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514129#M138626</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-17T15:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: DO-LOOP Index - Why is Index not the last value specified but number greater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514131#M138627</link>
      <description>&lt;P&gt;this example has the whys included.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.LOOP;
X = 0;
do Index = 1 to 5 by 3;
/* the variable x is set at this point only if the condition is met*/
X = Index;&lt;BR /&gt;output;
end;
/* while the variable xy is set at this point after the do loop is completed */
xy=index;&lt;BR /&gt;output;
run;




data WORK.LOOP2;
X = 0;
do Index = 1 to 5 by 2;
/* the variable x is set at this point only if the condition is met*/
X = Index;&lt;BR /&gt;output;
end;
/* while the variable xy is set at this point after the do loop is completed */
xy=index;&lt;BR /&gt;output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Nov 2018 15:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514131#M138627</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-17T15:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: DO-LOOP Index - Why is Index not the last value specified but number greater?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514448#M138737</link>
      <description>&lt;P&gt;Thanks for all the suggestions!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I actually tried the DEBUG step, but I am currently using SAS Studio online and hit an error with DEBUG saying it could not initialize.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI for anyone else that comes across this thread please note this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Analytics-U/Debug-option-in-Data-Step-does-not-work/td-p/197405" target="_blank"&gt;https://communities.sas.com/t5/SAS-Analytics-U/Debug-option-in-Data-Step-does-not-work/td-p/197405&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though I never knew that SAS had a DEBUG option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This makes more sense now, thanks everyone!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 14:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-Index-Why-is-Index-not-the-last-value-specified-but/m-p/514448#M138737</guid>
      <dc:creator>rodneyc8063</dc:creator>
      <dc:date>2018-11-19T14:27:56Z</dc:date>
    </item>
  </channel>
</rss>

