title: proc sql join in SAS that is closest to a date
body: <p>How can I do a one-to-many join between two datasets with proc sql in SAS to obtain the record in Dataset B is closest to a value in Dataset A?</p>
  
  <p><strong>Dataset A</strong></p>
  
  <pre><code>#Patient     #Date of Dose
  001                 2020-02-01
  </code></pre>
  
  <p><strong>Dataset B</strong></p>
  
  <pre><code># Patient        # Lab Test         #Date of Test     # Value 
  001            Test 1           2020-01-17      6
  001            Test 1           2020-01-29      10
  </code></pre>
  
  <p>I want to do the join to select the second record in Dataset B, the record with a "Date of Test" that is the closest (less than or equal to) to the "Date of Dose" in the first dataset.</p>