```Date: Tue, 20 Jul 2010 02:17:58 +0000 Reply-To: toby dunn Sender: "SAS(r) Discussion" From: toby dunn Subject: Re: Bona fide DO-loop bug (was: Re: Combining iterative DO and UNTIL condition) Comments: To: iw1sas@gmail.com In-Reply-To: Content-Type: text/plain; charset="iso-8859-1" Ian, I would say that yes: do x = 1, 2, 3 until (x = 2) ; Would be a bit usless as the exit condition is relient on the index variable. Which I find absured unless one, as in the previous examples, uses it solely for example purposes. I do like the grouping concept, So try something like this: Do X = (1, 2, 3) Until (Y = 0) ; Y = < pick some code> ; End ; Here Y is calculated inside the loop and the exit criteria for the do loop is dependent on the value of Y. But again one could do this : Do X = 1 To 3 Until (Y = 0) ; Y = < pick some code> ; End ; So lets make it more realistic: Do X = (5, 7, 8, 10, 11, 13, 23) Until (Y = 0) ; Y = < pick some code that requires the value of X in it> ; End No we know we want to loop over the values in the index list only that amount unless the value of Y reaches 0 first, then we want to terminate the loop. One could do something like: Array XX (*) 5 7 8 10 11 13 23 ; Do X = 1 By 1 To Dim( XX ) Until( Y = 0 ) ; Y = < pick some code that requires the value of X in it> ; End ; But then I have to ask why do we need to create an Array and not just use the list directly in the Do Loop. I know its not that much of a great leap or effort but still depending on where the Do-Loop is in the data step and how big it is it will be separated from array possibly by many lines.... Ill be damned if I didn;t eventually end up where you did but still want the functionaliy of having the Until be in effect for the whole list of index values. Toby Dunn "Don't bail. The best gold is at the bottom of barrels of crap." Randy Pausch "Be prepared. Luck is where preparation meets opportunity." Randy Pausch > Date: Mon, 19 Jul 2010 21:42:34 -0400 > From: iw1sas@GMAIL.COM > Subject: Bona fide DO-loop bug (was: Re: Combining iterative DO and UNTIL condition) > To: SAS-L@LISTSERV.UGA.EDU > > Paul, > > As others have said the comma separates parts in the DO-loop specification. > Each part has its own conditional clause. Consequently, in > > do x = 1, 2, 3 until (x = 2) ; > > the UNTIL says stop when the 3 becomes a 2 with the test for this at the > bottom of the loop. I find that very hard to accept as a bug. > > Now you might not like the design, so let's look at it. Suppose we extend > the notation to include a list of items as in > > do x = (1, 2, 3) until (x = 2) ; > > This syntax would work and give you want and not change past behavior. > > Now I have to ask why anyone would want this behavior. As I type "1, 2, 3" > I know when to stop typing the list at 2, so why should I need the compiler's > help with this problem? > > In contrast > > do x = 1 to 3 until (eof) ; > set w end = eof ; > ... > end ; > > is an important construction. Here the is the integers are counting, but > I don't know how far to count just that 3 is an upper bound. I want to add > an observation number, but I don't know how far to go since that is > determined by the file, NOT the list. > > On the other hand, I might have a language with list objects. In such a > language you might expect > > do x in list until (condition) ; > > Here the creator of LIST may have no knowledge of the loop and the loop > has know prior knowledge of how the condition is related to LIST. However, in > languages that accept list objects, a word like BREAK (SAS LEAVE) is used > inside the loop to break out of it, probably because it is more flexible. > The UNTIL is a much older construct. > > To combine the list of primes and the UNTIL condition Robert could use > > array p (18) _temporary_ > (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,59,71,73) ; > do i = 1 to 18 until ( QUOT = 1 ) ; > DIV = p[i] ; > ... > end ; > > Ian Whitlock > =============== > > Date: Sun, 18 Jul 2010 16:30:44 -0400 > Reply-To: Paul Dorfman > Subject: Bona fide DO-loop bug (was: Re: Combining iterative DO and UNTIL > condition) > Comments: To: Robert Rosofsky > > Robert, > > > My first impulse was in the direction of DATA _NULL_'s conjecture, but then > simple testing has shown than you have discovered a 100 per cent bona fide > bug. Consider: > > > data _null_ ; > do x = 1, 2, 3 until (x = 2) ; > put x= ; > end ; > put "---"; > do x = 1, 2, 3 ; > put x= ; > if x = 2 then leave ; > end ; > put "---"; > do x = 1 by 1 until (x = 2) ; > put x= ; > end ; > put "---"; > do x = 1 to 3 until (x = 2) ; > put x= ; > end ; > run ; > > > Result: > > > x=1 > x=2 > x=3 > --- > x=1 > x=2 > --- > x=1 > x=2 > --- > x=1 > x=2 > > > First, I do not see any reason why DO X=1,2,3 should behave any differently > from DO X=1 TO 3. Second, even if there were a good reason, then DO X=1,2,3 > UNTIL (X=2) should not behave any differently from DO X=1,2,3 with an > equivalent LEAVE, but it does. > > > Obviously, precision considerations, which might arise from your QUOT being > the result of a division, are absent from the test above. Running SAS9.2 TS > Level 2M0 on XP_Pro platform. > > > I will consider it a bona fide bug in need to be addressed unless someone > could concoct a very convincing reason why it might be a feature. > > Kind regards > ------------ > Paul Dorfman > Jax, FL > ------------ > > > > > On Sun, 18 Jul 2010 11:48:13 -0400, Robert Rosofsky > wrote: > > > >I'm attempting to combine an interative DO loop and an UNTIL condition. > >The purpose of the UNTIL condition is to quit the loop if all values of the > >index variable do not need to be evaluated. > > > >When Div=47, the processing sets QUOT = 1 and this should terminate the > >loop. However, the loop does not terminate as shown in the following > >excerpt from the LOG. Through use of PUT statements we can see that even > >when QUOT=1, the loop continues through Div values of 59, 71, & 73. > > > >Any thoughts? Thanks for your help. > > > >5261 data COMB; > >5262 length COMB \$30; > >5263 set LL_VAC2(keep=STUDYID SEASON VACNUM VXCOMB Prime); > >5264 QUOT= VXCOMB / Prime; > >5265 do Div=2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,59,71,73 until > >(QUOT=1); > >5266 put "Entering loop " VXCOMB= div= prime= QUOT=; > >5267 if Div ne Prime then do; > >5268 put "Div ne Prime: Possible condition "; > >5269 if mod(QUOT,Div)=0 then do; > >5270 put "Modulus=0 "; > >5271 COMB=left(trim(COMB) || " " || trim(put(Div,VacAbbr.))); > >5272 put COMB=; > >5273 QUOT= QUOT / Div; > >5274 end; > >5275 end; > >5276 end; > >5277 run; > > > >Entering loop VXCOMB=197353 Div=2 Prime=13 QUOT=15181 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=3 Prime=13 QUOT=15181 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=5 Prime=13 QUOT=15181 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=7 Prime=13 QUOT=15181 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=11 Prime=13 QUOT=15181 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=13 Prime=13 QUOT=15181 > >Entering loop VXCOMB=197353 Div=17 Prime=13 QUOT=15181 > >Div ne Prime: Possible condition > >Modulus=0 > >COMB=HepA > >Entering loop VXCOMB=197353 Div=19 Prime=13 QUOT=893 > >Div ne Prime: Possible condition > >Modulus=0 > >COMB=HepA Hib > >Entering loop VXCOMB=197353 Div=23 Prime=13 QUOT=47 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=29 Prime=13 QUOT=47 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=31 Prime=13 QUOT=47 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=37 Prime=13 QUOT=47 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=41 Prime=13 QUOT=47 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=43 Prime=13 QUOT=47 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=47 Prime=13 QUOT=47 > >Div ne Prime: Possible condition > >Modulus=0 > >COMB=HepA Hib PNEU > >Entering loop VXCOMB=197353 Div=59 Prime=13 QUOT=1 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=71 Prime=13 QUOT=1 > >Div ne Prime: Possible condition > >Entering loop VXCOMB=197353 Div=73 Prime=13 QUOT=1 > >Div ne Prime: Possible condition _________________________________________________________________ Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1```

Back to: Top of message | Previous page | Main SAS-L page