<?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 Do Until  with a SET statement logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-Until-with-a-SET-statement-logic/m-p/259639#M50240</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I don't understand the logic of using the a do until loop in this context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is a data&amp;amp;colon;&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;data ab;
input a  b ;
cards;
1    1
1    1  
1    2  
2    1  
2    1   
2    2  
2    2 
;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code works fine, it uses a do Until loop before the SET statment :&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;data out ;               
   do until (last.a) ;   
      do until (last.b) ;
         set ab ;        
         by a b ;   
      end ;                     
   end ;                 
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it output last.a and last.b.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; b&lt;/P&gt;
&lt;P&gt;- &amp;nbsp; -&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone explain me the difference with this code ? &amp;nbsp;In this code the loop is after the SET statment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data out ;  
    set ab ; 
    by a b ;              
     do until (last.a) ;   
        do until (last.b) ;    &lt;BR /&gt;         put a=  b=;
       end ;                     
     end ;                 
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The loop keeps iterating and stays at value&amp;nbsp;value a=1 and b=1. Why does the loop stuck &amp;nbsp;on those valueand does not iterate to the next records as in the first case above ? And why does the loop in the first case not stuck ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;saskapa&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>Tue, 29 Mar 2016 12:43:13 GMT</pubDate>
    <dc:creator>saskapa</dc:creator>
    <dc:date>2016-03-29T12:43:13Z</dc:date>
    <item>
      <title>Do Until  with a SET statement logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Until-with-a-SET-statement-logic/m-p/259639#M50240</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I don't understand the logic of using the a do until loop in this context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is a data&amp;amp;colon;&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;data ab;
input a  b ;
cards;
1    1
1    1  
1    2  
2    1  
2    1   
2    2  
2    2 
;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code works fine, it uses a do Until loop before the SET statment :&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;data out ;               
   do until (last.a) ;   
      do until (last.b) ;
         set ab ;        
         by a b ;   
      end ;                     
   end ;                 
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it output last.a and last.b.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; b&lt;/P&gt;
&lt;P&gt;- &amp;nbsp; -&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone explain me the difference with this code ? &amp;nbsp;In this code the loop is after the SET statment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data out ;  
    set ab ; 
    by a b ;              
     do until (last.a) ;   
        do until (last.b) ;    &lt;BR /&gt;         put a=  b=;
       end ;                     
     end ;                 
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The loop keeps iterating and stays at value&amp;nbsp;value a=1 and b=1. Why does the loop stuck &amp;nbsp;on those valueand does not iterate to the next records as in the first case above ? And why does the loop in the first case not stuck ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;saskapa&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>Tue, 29 Mar 2016 12:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Until-with-a-SET-statement-logic/m-p/259639#M50240</guid>
      <dc:creator>saskapa</dc:creator>
      <dc:date>2016-03-29T12:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Do Until  with a SET statement logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Until-with-a-SET-statement-logic/m-p/259642#M50241</link>
      <description>&lt;P&gt;The short answer is when you DO UNTIL you need logic in the loop that will eventually cause the until expression to become true. &amp;nbsp;Otherwise infinite loop.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 12:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Until-with-a-SET-statement-logic/m-p/259642#M50241</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-29T12:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Do Until  with a SET statement logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Until-with-a-SET-statement-logic/m-p/259643#M50242</link>
      <description>&lt;P&gt;The longer answer:&amp;nbsp; you need to understand the SET statement.&amp;nbsp; When it executes, it is not merely a label that tells SAS where to find observations.&amp;nbsp; Rather, it is an instruction to read the next observation.&amp;nbsp; That's just one observation, not a bunch of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in the top program, each iteration through the loop reads a single observation.&amp;nbsp; Eventually, the UNTIL condition becomes true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the bottom program, the SET statement reads the first observation.&amp;nbsp; Then the loop begins, and the data values never change because no additional observations are being read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At an introductory level of using SAS, students tend to think of the SET statement as a label to indicate the source of observations.&amp;nbsp; The real process is much more complex than that.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 12:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Until-with-a-SET-statement-logic/m-p/259643#M50242</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-29T12:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Do Until  with a SET statement logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Until-with-a-SET-statement-logic/m-p/259829#M50327</link>
      <description>&lt;P&gt;Thanks Astounding. I understand better know..Besides, it is&amp;nbsp;&amp;nbsp;looks obvious now &amp;nbsp;why my second code leads to&amp;nbsp;a contiuous loopwhile in my first code not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;saskapa&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 18:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Until-with-a-SET-statement-logic/m-p/259829#M50327</guid>
      <dc:creator>saskapa</dc:creator>
      <dc:date>2016-03-29T18:11:57Z</dc:date>
    </item>
  </channel>
</rss>

