title: How to transpose data with multiple observations for the id variable in SAS?
body: <p>I am wondering the best way to transpose data in SAS when I have multiple occurances of my id variable.  I know I can use the let option in the proc transpose statement to do this, but I do not want to get rid of any data, as I intend to compute averages.</p>
  
  <p>Here is an example of my data and my code:</p>
  
  <pre><code>data grades;
  input student testnum grade;
  cards;
  1   1   30
  1   1   25
  1   2   45
  1   3   67
  2   1   22
  2   2   63
  2   2   12
  2   2   77
  3   1   22
  3   1   17
  3   2   14
  3   4   17
  ;
  run;
  
  proc sort data=grades;
      by student testnum;
  run;
  
  proc transpose data=grades out=trgrades;
      by student;
      id testnum;
      var grade;
  run;
  </code></pre>
  
  <p>Here is how I would like my resulting dataset to look:</p>
  
  <pre><code>student testnum1 testnum2 testnum3 testnum4   avg12     avg34
  1         30        45      67       .         33.33     67    
  1         25        .        .       .         33.33     67
  2         22        63       .       .         43.5      .
  2         .         12       .       .         43.5      .
  2         .         77       .       .         43.5      .
  3         22        14       .      17         53        17
  3         17        .        .       .         53        17
  </code></pre>
  
  <p>I want to use this new dataset (not sure how yet) to create the new columns that are the average score of all testnum1's and testnum2's for a student (avg12) and the average of all testenum3's and testnum4's (avg34) for a student.</p>
  
  <p>There may be a much more efficient way to do this but I am stumped.
  Any advice is appreciated.</p>