<?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: What happen with Do j=i-1 to j=i-3. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877986#M346875</link>
    <description>&lt;P&gt;For the 5th observation, you have &lt;EM&gt;&lt;STRONG&gt;i=5&lt;/STRONG&gt;&lt;/EM&gt; and &lt;EM&gt;&lt;STRONG&gt;value=8&lt;/STRONG&gt;&lt;/EM&gt;, which activates this loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    do j=i-1 to j=i-3 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;J starts the loop at 4, as expected, but does not end at J=2.&amp;nbsp; Instead, it ends at J=0 (more on that below), when the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set have (keep=t value rename=(t = tt value=v)) point=j;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;attempts to read the non-existent observation 0, at which point the automatic variable &lt;EM&gt;&lt;STRONG&gt;_ERROR_&lt;/STRONG&gt;&lt;/EM&gt; is set to 1 for that observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, why doesn't the loop&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    do j=i-1 to j=i-3 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;stop at J=2 when i=5?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see no ready answer to that question.&amp;nbsp; The SET statement with the "point=j" option reads obs 4, then obs 3, all the way to the failed obs 0 (I tested this by putting a "put j=;" statement after the SET statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This sequence happens even if I change the end condition from j=i-3 to, say j=i-1, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    do j=i-1 to j=i-1 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It doesn't stop any earlier.&amp;nbsp; It keep SETting obs until the _ERROR_=1 condition is generated by pointing at obs zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But lest you think generating _ERROR_=1 is always enough to stop a loop containing a SET .... POINT= statement, then type&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    do j=i-1 to (j=i)-3 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will make attempts to read obs -1, -2, -3, even after _ERROR_=1 due to failed read of obs 0.&amp;nbsp; That's "logical" since (j=i) is always 0, so (j-1)-3 is minus 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the _ERROR_=1 condition seems to selectively stop the loop iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 29 May 2023 04:52:50 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-05-29T04:52:50Z</dc:date>
    <item>
      <title>What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877982#M346873</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I know the correct syntax should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do j=i-1 to i-3 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;do j=i-1 to &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&lt;U&gt;j&lt;/U&gt;&lt;/STRONG&gt;&lt;/FONT&gt;=i-3 by -1 until (found=1);&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, SAS still run this command and I don't know what really happen there.&lt;/P&gt;
&lt;P&gt;Look like SAS will run all the way to the end of data.&lt;/P&gt;
&lt;P&gt;I wonder why SAS doesn't give at least a warning?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id t value;
datalines;
1 1 2
1 2 5
1 3 6
1 4 7
1 5 8
1 6 9
;run;

data want;
set have;
i+1;
if value=8 then do;
found=0;
count=0;
do j=i-1 to j=i-3 by -1 until (found=1);
	set have (keep=t value rename=(t = tt value=v)) point=j;
	count=count+1;
	if v=1 then do;
		target=tt;
		found=1;
		end;
end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 02:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877982#M346873</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2023-05-29T02:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877985#M346874</link>
      <description>&lt;P&gt;Consider how SAS evaluates this statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do j=i-1 to j=i-3 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here, "j=i-3" is a logical expression, which SAS automatically evaluates.&amp;nbsp; Evaluating a logical expression yields 0 if the expression is false, or 1 if the expression is true.&amp;nbsp; So the software evaluates this as one of these two possibilities:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do j=i-1 to 0 by -1 until (found=1);

do j=i-1 to 1 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;More specifically, j begins with a missing value.&amp;nbsp; But i will not be missing since incrementing with the statement i+1; assigns a nonmissing value to i.&amp;nbsp; So the software executes this as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do j=i-1 to 0 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some SAS puzzles have been built around this theme of logical expressions, using a statement such as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do j=1 to 5, i=4 to 6;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How many times should that loop execute, and with what values for j and i ?&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 03:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877985#M346874</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-05-29T03:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877986#M346875</link>
      <description>&lt;P&gt;For the 5th observation, you have &lt;EM&gt;&lt;STRONG&gt;i=5&lt;/STRONG&gt;&lt;/EM&gt; and &lt;EM&gt;&lt;STRONG&gt;value=8&lt;/STRONG&gt;&lt;/EM&gt;, which activates this loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    do j=i-1 to j=i-3 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;J starts the loop at 4, as expected, but does not end at J=2.&amp;nbsp; Instead, it ends at J=0 (more on that below), when the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set have (keep=t value rename=(t = tt value=v)) point=j;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;attempts to read the non-existent observation 0, at which point the automatic variable &lt;EM&gt;&lt;STRONG&gt;_ERROR_&lt;/STRONG&gt;&lt;/EM&gt; is set to 1 for that observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, why doesn't the loop&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    do j=i-1 to j=i-3 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;stop at J=2 when i=5?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see no ready answer to that question.&amp;nbsp; The SET statement with the "point=j" option reads obs 4, then obs 3, all the way to the failed obs 0 (I tested this by putting a "put j=;" statement after the SET statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This sequence happens even if I change the end condition from j=i-3 to, say j=i-1, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    do j=i-1 to j=i-1 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It doesn't stop any earlier.&amp;nbsp; It keep SETting obs until the _ERROR_=1 condition is generated by pointing at obs zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But lest you think generating _ERROR_=1 is always enough to stop a loop containing a SET .... POINT= statement, then type&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    do j=i-1 to (j=i)-3 by -1 until (found=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will make attempts to read obs -1, -2, -3, even after _ERROR_=1 due to failed read of obs 0.&amp;nbsp; That's "logical" since (j=i) is always 0, so (j-1)-3 is minus 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the _ERROR_=1 condition seems to selectively stop the loop iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 04:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877986#M346875</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-05-29T04:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877987#M346876</link>
      <description>&lt;P&gt;Try it and see for yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=0 to 5;
    put i= @;
    do j=i-1 to j=i-3 by -1 ;
      put j= @ ;
    end;
    put;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;28   data _null_;
29     do i=0 to 5;
30       put i= @;
31       do j=i-1 to j=i-3 by -1 ;
32         put j= @ ;
33       end;
34       put;
35     end;
36   run;

i=0
i=1 j=0
i=2 j=1
i=3 j=2 j=1
i=4 j=3 j=2 j=1 j=0
i=5 j=4 j=3 j=2 j=1 j=0
&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;The first thing to notice is this is the exact same result you get if you add in some grouping to control the order of operations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do j=i-1 to j=(i-3) by -1 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So let's show all of the values being evaluated here and see how the change as J is decremented.&amp;nbsp; We have the value I,&amp;nbsp; And the value of (I-3).&amp;nbsp; Those do not change as the loop progresses.&amp;nbsp; Then J starts at I-1 and decrements by one after each "run".&amp;nbsp; To decide whether to run the do loop it needs to compare if the value of J is less than the value of J=(i-3).&lt;/P&gt;
&lt;LI-SPOILER&gt;&lt;BR /&gt;
&lt;PRE&gt;I  (i-3)   J  j=(i-3) J too small?
0   -3    -1    0     STOP

1   -2     0    0     RUN
1   -2    -1    0     STOP

2    0     1    0     RUN
2    0     0    1     STOP

3    0     2    0     RUN
3    0     1    0     RUN
3    0     0    1     STOP

4    1     3    0     RUN
4    1     2    0     RUN
4    1     1    1     RUN
4    1     0    0     RUN
4    1    -1    0     STOP
&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 13:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877987#M346876</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-29T13:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877997#M346883</link>
      <description>Amazing trick! Does sombody really use it in reality?</description>
      <pubDate>Mon, 29 May 2023 07:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/877997#M346883</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-05-29T07:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878025#M346888</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270406"&gt;@whymath&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This particular trick?&amp;nbsp; No.&amp;nbsp; But even beginning programmers use logical expressions all the time.&amp;nbsp; For example, consider:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.state then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is no comparison there.&amp;nbsp; First.state is either 1 or 0, and the software considers 1 to be true and 0 to be false.&amp;nbsp; So there is no need for:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.state=1 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Actually, the evaluation of logical expressions goes beyond 1 and 0.&amp;nbsp; The software considers 0 and missing values to be false, and all other values (including negative numbers) to be true.&amp;nbsp; So consider a simple statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a = b / c;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When c is 0, the software notes that division by zero took place, and tracks how many times it happened.&amp;nbsp; &amp;nbsp;It also runs up the bill, taking vastly more CPU time.&amp;nbsp; Similarly, when c is missing, the result is that a missing value gets generated.&amp;nbsp; Again, the software runs up the bill (CPU time, that is), with no usable numeric result.&amp;nbsp; So if you have lots of missing values of zeros for C, it can be faster to use this statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if c then a = b / c;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The IF clause treats C as a logical expression (false for missings and zero, but true for all other values.&amp;nbsp; So there is no attempt to calculate anything when C is missing or zero.&amp;nbsp; I don't think I can come up with a realistic use for:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to 5, j=5 to 7;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 May 2023 12:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878025#M346888</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-05-29T12:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878045#M346895</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270406"&gt;@whymath&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Amazing trick! Does sombody really use it in reality?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Intentionally? I would say only by those who specialize in writing obscure code in the hopes of job security as no one else could follow it easily. &lt;span class="lia-unicode-emoji" title=":smiling_face_with_horns:"&gt;😈&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 15:05:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878045#M346895</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-29T15:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878057#M346901</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Some SAS puzzles have been built around this theme of logical expressions, using a statement such as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do j=1 to 5, i=4 to 6;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How many times should that loop execute, and with what values for j and i ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The Puzzle Master casually drops a masterpiece.&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;, maybe steal this for a #sasensei question.&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 15:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878057#M346901</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-29T15:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878064#M346905</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;&amp;nbsp;That question would be a sneaky one! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 16:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878064#M346905</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-29T16:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878068#M346907</link>
      <description>&lt;P&gt;The DO-Loop in it's most general form (according to the documentation) is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DO index-variable
 =  start_expression1 &amp;lt;TO stop_expression1&amp;gt;&amp;lt;BY increment_expression1&amp;gt; &amp;lt;WHILE(expression1)| UNTIL(expression1)&amp;gt;
 &amp;lt;, start_expression2 &amp;lt;TO stop_expression2&amp;gt;&amp;lt;BY increment_expression2&amp;gt; &amp;lt;WHILE(expression2)| UNTIL(expression2)&amp;gt;&amp;gt;
  ...
 &amp;lt;, start_expressionN &amp;lt;TO stop_expressionN&amp;gt;&amp;lt;BY increment_expressionN&amp;gt; &amp;lt;WHILE(expressionN)| UNTIL(expressionN)&amp;gt;&amp;gt;
  ;

...moreSAS statements...

END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;lt;&amp;gt; - means optional element&lt;/P&gt;
&lt;P&gt;| - means exclusive or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in your case the :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;do j=i-1 to j=i-3 by -1 until (found=1);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is perfectly good example of a do-loop with&lt;/P&gt;
&lt;P&gt;start expression:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;i-1&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;stop expression:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;j=i-3&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;by expression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;-1&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and until condition:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;found=1&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, as others wrote, you will get the loop from i-1 to 0 or 1 (depends how the stop expression evaluates) by -1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the&amp;nbsp; way&amp;nbsp; looping with&amp;nbsp; point wont give you any warning even for negative values, you will get only one&amp;nbsp; "put log" for _error_=1 at the very end of processing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    data x;
2      do point=-1,-2,-3,-4,-5,-6,-7;
3        set sashelp.class point=point;
4        output;
5      end;
6
7      stop;
8    run;

point=-7 Name=  Sex=  Age=. Height=. Weight=. _ERROR_=1 _N_=1
NOTE: The data set WORK.X has 7 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Doc. only states:&amp;nbsp;&lt;/P&gt;
&lt;DIV class="xisDoc-refBlock"&gt;
&lt;DIV class="xisDoc-syntax"&gt;
&lt;DIV class="xisDoc-syntaxDescription"&gt;
&lt;DIV class="xisDoc-otherArgGroup"&gt;
&lt;DIV id="p0u2yq8x2b1fu4n1m0d5hzam9hjv" class="xisDoc-argDescriptionPair"&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;SECTION class="xisDoc-tableWrap"&gt;
&lt;TABLE class="xisDoc-summary"&gt;
&lt;TBODY&gt;
&lt;TR id="p03dhefh9jnibln0zt2ujgow58yd"&gt;
&lt;TD class="xisDoc-summaryText"&gt;
&lt;DIV class="xisDoc-caution"&gt;
&lt;P class="xisDoc-paraSimple"&gt;If SAS reads an invalid value of the POINT= variable, it sets the automatic variable _ERROR_ to 1.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/SECTION&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thinking on where such "conditional" loop could be used, for short list of variables cumulative condition like below could be a use case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;resetline;
data have;
input a b c;
cards;
1 2 3
4 5 6
7 8 9
;
run;

data want;
  set have;
  do i=a&amp;gt;5, b&amp;gt;5, c&amp;gt;5;
    cnt+i;
  end;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 17:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878068#M346907</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-29T17:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878142#M346937</link>
      <description>You really study SAS in deeply, thank you, Astounding.</description>
      <pubDate>Tue, 30 May 2023 02:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878142#M346937</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-05-30T02:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: What happen with Do j=i-1 to j=i-3.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878143#M346938</link>
      <description>Agree with you. I may use it in code golf game but not in production.</description>
      <pubDate>Tue, 30 May 2023 02:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-happen-with-Do-j-i-1-to-j-i-3/m-p/878143#M346938</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-05-30T02:04:58Z</dc:date>
    </item>
  </channel>
</rss>

