Hi all, I have the following situation. I have two data sets (DS1 and DS2) that I want to use as a source to create a third data set (DS3). In short, the third data set (DS3) will be DS1 with an extra variable as the sum of variable X. To get the sum, you use the dates in DS1 and then sum any X variable between the previous date and current date defined in DS1. For example for A1 Visit 1, sum(X)={sum of X where date<=07/01/14}; for A1 Visit 2, sum(X)={sum of X where 07/01/14<date<=08/02/14}; etc. This code would have have to work across different subjects. I tried to use merge, first.Subject last.Subject, etc but this one stumps me. I'm not sure if a hash table would work here. I am not proficient in proc sql so if there is a data step option would be preferred but an sql statement will do as well. Thank you for your help! DS1 Subject Visit Date A1 1 07/01/14 A1 2 08/02/14 A1 3 08/15/14 A2 1 05/14/15 A2 2 07/22/15 data ds1; input subid $ visit date mmddyy8.; datalines; A1 1 07/01/14 A1 2 08/02/14 A1 3 08/15/14 A2 1 05/14/15 A2 2 07/22/15 ; DS2 Subject Date X A1 06/02/14 3 A1 07/01/14 0 A1 08/02/14 1 A1 08/10/14 10 A1 08/15/14 2 A2 05/14/15 2 A2 05/23/15 3 A2 06/01/15 0 A2 07/22/15 7 data ds2; input subid $ date mmddyy8. x; datalines; A1 06/02/14 3 A1 07/01/14 0 A1 08/02/14 1 A1 08/10/14 10 A1 08/15/14 2 A2 05/14/15 2 A2 05/23/15 3 A2 06/01/15 0 A2 07/22/15 7 ; DS3 Subject Visit Date Sum(X) A1 1 07/01/14 3+0=3 A1 2 08/02/14 1 A1 3 08/15/14 10+2=12 A2 1 05/14/15 2 A2 2 07/22/15 3+0+7=10
... View more