title: Transposing Data in SPSS
body: <p>I have a SPSS data file with only four variables (columns), that I'm trying to transpose. The original file looks like:</p>
  
  <pre><code>ItemID  StudentID  Score   Weight  
  123     a1         1.0       1.0
  123     a1         0.0       1.0
  123     a2         1.0       1.0
  124     a1         0.0       5.0
  124     a2         1.0       5.0
  </code></pre>
  
  <p>and what I am trying to get would use StudentID as the identifier variable, but also create new variables based upon the ItemID. So the data above would be transposed into:  </p>
  
  <pre><code>StudentID    score_123   weight_123   score_124   weight_124
  a1           1.0         1.0          0.0         5.0   
  a2           0.0         1.0          1.0         5.0
  </code></pre>
  
  <p>The syntax I've tried is:</p>
  
  <pre><code>SORT CASES BY StudentID ItemID. 
  CASESTOVARS 
  /ID=StudentID 
  /INDEX=ItemID
  /GROUPBY=INDEX 
  /VIND ROOT=ind.
  </code></pre>
  
  <p>But this clearly fails because of the repeated measures in the data file; StudentID and ItemID are sometimes repeated. (As a side note, I have no other variables to work from). </p>
  
  <p>Do I have to remove duplicate cases, or is there another way to achieve this? I'm reluctant to drop duplicates because I don't know which cases might matter (without other information, identifying duplicates as primary/last is arbitrary). The data file has several million cases, as well. </p>
  
  <p>I'm using SPSS stats v. 24 with python installed. I also have access to R but have never used it. </p>
  
  <p>Any help that can be passed along would be extremely appreciated!</p>