title: SAS row comparisons and queries? or other solution needed. I'm stumped
body: <p>I have a situation where for each unique observation of casenum I would like to run varies queries and arithmatic operations between various observations of 'code' for that 'casenum' (see below). For example for casenum 1234567 I would like subtract data for code 0200 - code 0234 or 531 - 53. Please keep in mind that there are thousands of observations in this dataset. Is there an easy way to do this or to do row comparisons with the particular.</p>
  
  <p><em>Please note casenum and code are character variables and data is a numeric variable</em></p>
  
  <p>Here is an example of how the dataset is structured:</p>
  
  <pre>
  casenum  code  data
  
  1234567  0123  4597  
  1234567  0234    53  
  1234567  0100   789  
  1234567  0200   531  
  1234567  0300   354  
  1111112  0123    79  
  1111112  0234    78  
  1111112  0100    77   
  1111112  0200  7954  
  1111112  0300    35
  </pre>
  
  <hr>
  
  <p>Here is the logic although likely syntactically incorrect of what I am trying to do.</p>
  
  <p>For code observations where casenum is the same, within those casenums<br>
  I would like it to determine,    if <em>data</em> for code 0234 + <em>data</em> for code  0100 - <em>data</em> for code 0123 ne  <em>data</em> for code 0200 then  newvariable = 'YES'</p>
  
  <p>In other words I'd like it to test if 53 + 789 - 4597 ne 531. after that and other similar kinds of tests run within casenum 1234567, I'd like it to move onto the next casenum, and run those same tests for that casenum.</p>
  
  <p>Keep in mind this dataset has hundreds of thousands of observations in it. </p>