# Finding the Lowest Value Classic List Threaded 4 messages Open this post in threaded view
|

## Finding the Lowest Value

 Hi List,   I have a battery of 4 repeated measures taken over a period of 9 weeks (so there are 36 variables).  I need to locate the week in which the lowest or minimum measure occurs.  I know I can write 36 separate "IF" statements, but that hardly seems efficient.   The idea is thus:     IF (MIN(wbc1 TO wbc9) = wbc1) lowest_week = 1. IF (MIN(wbc1 TO wbc9) = wbc2) lowest_week = 2. IF (MIN(wbc1 TO wbc9) = wbc3) lowest_week = 3. etc.   But as you can see, that's just inefficient.  (Granted, I could probably just copy and paste the IF statements and edit them all, and it would also take less time than it would to complete this request for assistance..  But that's just so..  inelegant.   Any suggestions are appreciated.   Thanks,   John
Open this post in threaded view
|

## Re: Finding the Lowest Value

 John, If i understand you correctly, the way to do this is to use Loop. In the code that follows, i assume that your variables (MA1 to MA9, MB1 to MB9, MC1 to MC9, and MD1 to MD9, the second character is the measure descriptor) are organized in the following manner in your dataset: MA1 to MA9, MB1 to MB9, MC1 to MC9, and MD1 to MD9. If they are not organized that way, you'll have to get them that way for this to work. Vector Measure=MA1 to MA9. Compute MAWeek=0. Compute #first=MA1. Loop #i=2 to 9. +  Do if (measure(#i) lt #first). +     Compute MAWeek=#i. +     Compute #first=measure(#i). +  End if. End loop. You'll need to repeat this for each of the variable sets. There may be a way to do this all at once if a Loop-end loop can be embedded in a Do repeat. Maybe somebody with more experience can comment. Gene Maguin