<?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: Help with Do Loop return incorrect result in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-Loop-return-incorrect-result/m-p/968785#M376633</link>
    <description>&lt;P&gt;I do not understand what the LEAVE statements are for.&amp;nbsp; What is it that you want to LEAVE?&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jun 2025 19:00:25 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-06-11T19:00:25Z</dc:date>
    <item>
      <title>Help with Do Loop return incorrect result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-Loop-return-incorrect-result/m-p/968777#M376631</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an issue with the result produced by the below loop code.&lt;/P&gt;
&lt;P&gt;Basically, when body_50 =1 bar[i], then look forward when condition: new row's low[j] &amp;lt; low[i] +&amp;nbsp;add_level_1[i] then mark:&lt;/P&gt;
&lt;P&gt;1 - entry_time = time[j]&lt;/P&gt;
&lt;P&gt;2 - entry_price =ceil(low[i] * 100) / 100+ add_level_1[i]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As shown in the picture attached, on the row 9:27, body_1 =1 with low[i] +&amp;nbsp;add_level_1[i] = 231.13 and SAS starts look forward.&lt;/P&gt;
&lt;P&gt;BUT it pick row 9:30 where low is 131.50 which is &lt;U&gt;bigger&lt;/U&gt; than&amp;nbsp;231.13. It means the condition is Not met and somehow SAS still pick that row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is very much appreciated.&lt;/P&gt;
&lt;P&gt;&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;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hhchenfx_2-1749665548842.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107752i09C967A91AA7CB71/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hhchenfx_2-1749665548842.png" alt="hhchenfx_2-1749665548842.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=ss; by tic date clock_time;run;

data ss1; set ss nobs=nobs;
drop i j_: out ;
format entry_time bigbar time9.;
i+1;
out=0;
by tic;
if  body_50=1 then do; 
	do j=i+1 to nobs until (out=1);
	set ss (keep=tic date clock_time low high rename = (tic=J_tic date=J_date clock_time=J_clock_time low=J_low high=J_high) ) point=j;

			low_plus_add_level_1=low+add_level_1 ;
			gap=(J_clock_time - clock_time) / 60;

	if date^=J_date or tic^=J_tic or J_clock_time&amp;gt;'15:30't then do; out=1; leave; end;
	else
	if gap&amp;lt;20 and J_low&amp;lt;=low+add_level_1 then do;
		 	entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_1;
			bigbar=clock_time;
			out=1; leave;
			end;
	else 
	if gap&amp;lt;60 and J_low&amp;lt;=low+add_level_3 then do;
		 	entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_3;
			bigbar=clock_time;
			out=1; leave;
			end;
	else 
	if gap&amp;lt;120 and J_low&amp;lt;=low+add_level_4 then do;
		 	entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_4;
			bigbar=clock_time;
			out=1; leave;
			end;
	else 
	if gap&amp;lt;180 and J_low&amp;lt;=low+add_level_5 then do;
		 	entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_5;
			bigbar=clock_time;
			out=1; leave;
			end;
	else 
	if gap&amp;gt;=180 and J_low&amp;lt;= low +add_level_6 then do;
			entry_time=J_clock_time;
			entry_price=ceil(low * 100) / 100+ add_level_6;
			bigbar=clock_time;
			out=1; leave;
			end;
end;
end;
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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-Loop-return-incorrect-result/m-p/968777#M376631</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2025-06-11T18:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Do Loop return incorrect result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-Loop-return-incorrect-result/m-p/968785#M376633</link>
      <description>&lt;P&gt;I do not understand what the LEAVE statements are for.&amp;nbsp; What is it that you want to LEAVE?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 19:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-Loop-return-incorrect-result/m-p/968785#M376633</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-11T19:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Do Loop return incorrect result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-Loop-return-incorrect-result/m-p/968787#M376635</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;Thanks for checking.&lt;/P&gt;
&lt;P&gt;I found the issue.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	if gap&amp;lt;60 then do;
			if J_low&amp;lt;=low+add_level_3 then do;
			 	entry_time=J_clock_time;
				entry_price=ceil(low * 100) / 100+ add_level_3;
				bigbar=clock_time;
				out=1; leave;
				end;end;
	else 
	if gap&amp;lt;120 then do;
			if J_low&amp;lt;=low+add_level_4 then do;
			 	entry_time=J_clock_time;
				entry_price=ceil(low * 100) / 100+ add_level_4;
				bigbar=clock_time;
				out=1; leave;
				end;end;
	else 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Jun 2025 19:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-Loop-return-incorrect-result/m-p/968787#M376635</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2025-06-11T19:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Do Loop return incorrect result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-Loop-return-incorrect-result/m-p/968788#M376636</link>
      <description>&lt;P&gt;Still don't understand why you have both the LEAVE and the UNTIL().&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 19:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-Loop-return-incorrect-result/m-p/968788#M376636</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-11T19:17:26Z</dc:date>
    </item>
  </channel>
</rss>

