title: Conditional Subtraction within the same column using SAS
body: <p>here is a portion of a data set I have named “antibody” :</p>
  
  <pre><code>Row          Subject        Type               Procedure           Measurement              Output
  1               500         Intial              Invasive             20                        20
  2               500          Initial            Surface              35                        35
  3               500          Followup          Invasive             54                        54-20
  4               428          Followup          Outer                 29                        29-10
  5               765          Seventh           Other                 13                       13-19
  6                500          Followup          Surface              98                       98-35
  7                428          Initial             Outer            10                        10                
  8                765          Initial              Other            19                        19     
  9                610          Third              Invasive            66                       66-17
  10               610          Initial             Invasive            17                       17
  </code></pre>
  
  <p>I was trying to use proc sql to perform this. The goal is to subtract the numbers in the "MEASUREMENT" column based on the "SUBJECT", "TYPE" and “PROCEDURE” columns. If two values in the “SUBJECT” column match and  two values in the “PROCEDURE” column match, then the initial measurement should be subtracted from the other measurement. For example, the initial measurement in row 1 (20) should be subtracted from the followup measurement in row 3 (54) because the subject (500) and procedure (Invasive) match. Furthermore, the initial measurement in row 8 (19) should be subtracted from the seventh measurement in row 5 (13) because the subject (765) and procedure (Other) match. The result should form the "OUTPUT" column.</p>
  
  <p>Thank you in advance!</p>