Hi, I need to merge two datasets by a unique id and then by nearest date with values carried forward. Code is as follows: data DATAONE; infile datalines dlm=' ' truncover; input id dateone date9. ; format dateone date9.; datalines; 1 27OCT22 1 27OCT22 1 27OCT22 1 28OCT22 1 29OCT22 1 30OCT22 1 31OCT22 1 01NOV22 1 02NOV22 1 03NOV22 ; run; proc print;run; data DATATWO; infile datalines dlm=' ' truncover; input id datetwo :date9. num ; format datetwo date9. ; datalines; 1 26OCT22 20 1 28OCT22 18 1 03NOV22 19 1 11NOV22 22 ; run; proc print;run; Want: DATATHREE (where dataset three is a merge of dataone with datettwo by unique ID and by datetwo <= dateone and values of datetwo and num are carried forward. Want DATATHREE as shown as below) Obs id dateone datetwo num 1 1 27OCT2022 26OCT2022 20 2 1 27OCT2022 26OCT2022 20 3 1 27OCT2022 26OCT2022 20 4 1 28OCT2022 28OCT2022 18 5 1 29OCT2022 28OCT2022 18 6 1 30OCT2022 28OCT2022 18 7 1 31OCT2022 28OCT2022 18 8 1 01NOV2022 28OCT2022 18 9 1 02NOV2022 28OCT2022 18 10 1 03NOV2022 03NOV2022 19
... View more