title: Categorize one table based on contents of a column in another table
body: <p>I appreciate some help with this task, which I find a bit challenging
  I have two tables:
  1- Table 1: Containing patients and their diagnosis coded according to ICD code system (the table has several thousand rows in reality)</p>
  
  <pre><code>Patient Diagnosis
  JOHN    A1
  ALEX    A12
  ZAK K12
  RICHARD A25
  SAM G3
  MANNY   H2
  </code></pre>
  
  <p>2- Table 2: basically contains a number of ICD diagnosis groups, for the sake of simplicity let us say we have three columns A, B, C each of which has rows representing a number of ICD diagnosis codes, here is a simplification:</p>
  
  <pre><code>Group A Group B Group C
  A12 A21 C13
  A25 A33 J12
  H12 G1  A1
  K12 K77 L5
  G1  J12 A12
  D3  A25 G3
  </code></pre>
  
  <p>What I would like to do is create a third table which is essentially Table 1 plus three more columns each for group A, B and C. The code would then go through every row and see if the ICD diagnosis in table 1 fits any of the diagnoses in Groups A, B and C and if so it would fill the corresponding cell with 1 otherwise 0. Here is the final table just to explain:</p>
  
  <pre><code>Diagnosis   Group A Group B Patient Group C
  A1  0   0   JOHN    1
  A12 1   0   ALEX    1
  K12 1   0   ZAK 0
  A25 1   1   RICHARD 0
  G3  0   0   SAM 1
  H2  0   0   MANNY   0
  </code></pre>
  
  <p>Could anyone please suggest how this can be done? The tables in reality are of course much much larger</p>