It is a somewhat difficult concept to pick up early on in your learning curve. However, that said, the code is taking control away from the way SAS normally works. The two do until loops read each record within a by group. Thus, the first loop reads the records: 2448 1 2448 3 and creates the array, check, with the values: check1 1 check2 . check3 1 Then, the second do loop again reads those same two records, but this time knows the values in the array check. Since the sum of check will only equal 3 if there were at least three records for id 2448 and, between those records, contained values 1, 2 and 3 for visit. Then the first loop reads the records for the next id, etc., etc.
... View more