I have the following data:
ID GROUP DATE
A GR1 12/01/2013
A GR1 09/04/2014
A GR1 01/03/2015
A GR2 04/04/2015
A GR2 08/21/2015
A GR1 01/05/2016
A GR1 06/28/2016
B GR2 11/01/2013
B GR2 06/04/2014
B GR2 04/15/2015
B GR3 11/04/2015
B GR2 03/21/2016
B GR2 07/05/2016
B GR1 06/28/2016
C GR2 01/16/2014
C GR2 06/04/2014
C GR2 04/15/2015
C GR3 11/04/2015
C GR2 03/21/2016
C GR2 06/05/2016
C GR1 06/28/2016
I want to get the difference that a person remains in each group. So, the new table will look like this:
ID GROUP DATE Diff
A GR1 12/01/2013
A GR1 09/04/2014
A GR1 01/03/2015 398
A GR2 04/04/2015
A GR2 08/21/2015 139
A GR1 01/05/2016
A GR1 06/28/2016 175
B GR2 11/01/2013
B GR2 06/04/2014
B GR2 04/15/2015 530
B GR3 11/04/2015
B GR2 03/21/2016
B GR2 07/05/2016 106
B GR1 06/28/2016
C GR2 01/16/2014
C GR2 06/04/2014
C GR2 04/15/2015 454
C GR3 11/04/2015
C GR2 03/21/2016
C GR2 01/05/2016 76
C GR1 06/28/2016
The value in the column "Diff" 398 takes into account the difference "01/03/2015" - "12/1/2013". Similarly, any other difference.
Now my question is: how to get this difference? I cannot accept max (date) -min (date) in each group, because the group repeats at different times. In the same way, I cannot take the first point and the last point, as in SAS.
I would really appreciate if anyone would help me with the solution. I would prefer a solution in SAS, as the data size is very large. SO will not be stored in memory.
Hi,
source
share