Hi all, I am hoping you can help me! **Please help!!!!** 🙏 I am in SAS and I have datasets A and B with different measurements (relating to patient's health) as follows: Dataset A ID Date measurement_a 1 20JUN2013 52.3 1 12JUL2013 65.6 1 28NOV2014 37.4 1 02DEC2014 61.3 1 22SEP2015 40.5 1 15OCT2015 60.5 2 03JUN2011 46.5 2 19JUL2011 54.1 2 29OCT2012 53.6 Dataset B ID Date measurement_b 1 21MAR2007 43 1 13JUL2007 45 1 07APR2009 47 1 14MAY2009 46 1 16FEB2012 42 1 27AUG2012 53 1 12DEC2012 58 1 20JUN2013 56 1 10DEC2013 53 1 23MAY2014 49 1 17SEP2014 44 1 23SEP2015 40 2 16DEC2011 58 2 22AUG2012 54 2 20FEB2013 56 2 29MAY2013 53 What I am looking for is that if the date in Dataset B is within 6 months of the date in Dataset a, then a new variable called "time" will be added, saying 1,2,3,etc. for how many ever match with ** only measurement_a** length (in other words, I do not need to retain values of measurement_b if it does not match the date in Dataset a. Here is an example of what I mean: Desired result/dataset ID Time measure_a measure_b 1 1 52.3 56 (Dataset B Date = 20JUN2013 - Matched exactly) 1 2 65.6 53 (Dataset B date = 10DEC2013 - Within six months of 12JUL2013 [Dataset A Date]) 1 3 37.4 44 (Dataset B date = 17SEP2014 - Within six months of 28NOV2014 [Dataset A Date]) 1 4 61.3 . (because 17SEP2014 [Dataset B] is closest to 28NOV2014 [Dataset A]) 1 5 40.5 40 (because 23SEP2015 [Dataset B] is closest to 22SEP2015 [Dataset A]) 1 6 60.5 . (No date in Dataset B that is within 6 months of Date in Dataset A [15OCT2015]) 2 1 46.5 . (See below) 2 2 54.1 58 (because 03JUL2011 [Dataset B] is closest to 19JUL2011 [Dataset A]) 2 3 53.6 54 (Dataset B date = 22AUG2012 - Within 6 months of Dataset A date = 29OCT2012) I have joined on ID but the times is proving difficult. I know it could be the difference in months in the "where" statement in the following code: PROC SQL; CREATE TABLE join_test as SELECT * FROM data_a as a LEFT_JOIN data_b as b ON a.id = b.id WHERE days(a.Date - b.Date) <= 180 ; QUIT; But this does not do the trick. Can some **please** help me? I really appreciate it. Thanks in advance.
... View more