loop to select the date closest to another date, for multiple variables
For each MRN ID, I would like to select the date (in OBSERVATION_DATE), in association with various columns (i.e. hdl, ldl, and vldl) that is closest to the dates listed in multiple other columns (i.e. Base, SixMonths, TwelveMonths, and TwentyFourMonths). So for example, for the rows that report HDL data, I would like to assess the dates found in OBSEVATION_DATE to find the date closest to Base, SixMonths, etc. There should be 4 new columns created for that example (one for each of the 4 time points listed). Additionally, for that example, I want another set of 4 columns created that have the value associated with the date that was identified in the other 4 new columns. So in total for my sample data,there should be 24 new columns (See below)