I need your help to find the result for the below table
pil1 pil2 timp Mdat inti
3Week 3Month 1Year 9/27/2013 40
1Week 1Month 1Year 9/27/2013 40
1Week 1Month 6Month 3/27/2013 42
1Week 1Month 2Week 10/11/2012 44
1Week 1Month 9Month 6/27/2013 45
1Week 1Month 1Month 10/27/2012 46
1Week 1Month Overnight 9/27/2012 47
1Week 1Month 3Month 12/27/2012 43
1Week 1Month 1Week 10/4/2012 41
1Week 8Month 1Year 9/27/2013 40
expected result is
pil1 pil2 timp Mdat inti
1Week 1Month 1Week 10/4/2012 41
1Week 1Month 1Month 10/27/2012 46
3Week 3Month 2Week 10/11/2012 44
3Week 3Month 3Month 12/27/2012 43
1Week 8Month 1Week 10/4/2012 41
1Week 8Month 1Year 9/27/2013 40
compare pil1 with timp,
if it is matched then put its mdat and inti value
if not matched then find the minimum value for that, for instance 2Week is smaller than 3week
so put 2week's mdat and inti values.
compare pil2 with timp,
if it is matched then put its mdat and inti value
if not matched then find the Maximum value for that, for instance 1year is higher than 8month
so put 1year's mdat and inti values.