title: Create a variable to hold an association with a max value in SPSS
body: <p>I need to create a variable to indicate the primary school a student is associated with. I have 5 school variables in one year for each student. The first school variable is always populated with the student’s 5 digit school code; if a student attended 5 schools in a year all 5 variables are populated; if they only attend 1 school, only the first variable is populated. I also have corresponding variables with the number of days a student was in each school, max 180. I need a variable with the 5-digit school code from the school where they attended most of the school year. If they only attended one school, it should be that school that they’re associated with, regardless of how many days they attended.  Can I use a DO IF command and loop to create this variable?  The syntax below is only for the first school, which is inefficient, and is not quite there, as it does not capture students who are under the 90 day threshold (i.e., only attended 1 school for less than 90 days).</p>
  
  <p>Update 8/2: I actually do need to capture students who are not present for 1/2 the year (90 days). There could be a student who attended 5 schools, with a few days at each, and possibly the max at one being 89. So regardless of how many days a student attended the school, I want to associate him with the school that he attended the most. Regarding whether a student attended two schools for the same number of days, taking the first is sufficient. Thank you for your replies.</p>
  
  <pre><code>
  
  
         DO IF  (TotalMembership_1011_sum.1 >= 90).
            RECODE SchCode_1011.1 (21 thru 93=Copy) INTO PrimarySchool_1011.
          END IF.
          VARIABLE LABELS  PrimarySchool_1011 'primary school 2010-11 (90+ days membership)'.
          EXECUTE.
  
  
  
  </code></pre>