|
|||
|
Tom,
I may be wrong, but I seem to remember that in a, "do index=startvalue to stopvalue by increment", there is an implicit "index+increment" calculation at the end of the loop and then the incremented index is compared to the stopvalue. If it exceeds the stopvalue the loop ends, otherwise the loop statements are executed. To stop the increment of the index when index=stopvalue would require additional code, as Howard's example demonstrates. Jim Simmons --- "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM> wrote: > It's not just IML. The DATA step DO works the same way. > Running > > data _null_; > do i = 1 to 3; end; > put i=; > run; > > produces > > i=4 > > If you don't like that, you can add a bit of seemingly > redundant code which > should tweak this side effect but not change other behavior. > Here it is: > > data _null_; > do i = 1 to 3 until (i=3); end; > put i=; > run; > > Result: > > i=3 > > On Wed, 20 Apr 2005 13:16:55 -0500, Thomas A. Schmitt > <schmitta@UWM.EDU> > wrote: > > >Hi All, > > > >This is more just a general question satisfy my curiosity > about the logic > of > >programming language. Why when going through a loop does the > count go one > >number higher than what you specified the loop to be? So, if > your loop is > i = 1 > >TO 5 why does i = 6 when the loop ends? The obvious answer to > me is to > simply > >end the loop. Does this issue have any potential problems? > Say, if you > would > >like to reference a position in a matrix based on the i > count. > > > >I noticed this when I had an outer loop of DO i = 1 TO 5 and > an inner loop > of DO > >k = 1 TO i. I wanted to keep a count of when the values were > equal after > >exiting the inner i loop, but the would always k = 6 while i > = 5. I solved > it > >by subtracting 1, but it just seems a little odd to me > because it only > loops > >through 5 times. Anyway, any explanations are appreciated. > > > >Tom > |
|
|
||||
|
||||
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: gettting out of the nested loop | Terjeson, Mark | Newsgroup comp.soft-sys.sas | 0 | 07-19-2005 04:22 PM |
| Re: Do Loop Counts in SAS IML | nospam@HOWLES.COM (Howard Schreier | Newsgroup comp.soft-sys.sas | 0 | 04-21-2005 02:21 AM |
| Re: Do Loop Counts in SAS IML | Jack Hamilton | Newsgroup comp.soft-sys.sas | 0 | 04-20-2005 10:23 PM |
| Re: Do Loop Counts in SAS IML | Schwarz, Barry A | Newsgroup comp.soft-sys.sas | 0 | 04-20-2005 07:28 PM |
| Do Loop Counts in SAS IML | Thomas A. Schmitt | Newsgroup comp.soft-sys.sas | 0 | 04-20-2005 06:16 PM |