I have a dataset like this:
data medication; infile datalines dsd truncover; input id $ start : ddmmyy10. next : ddmmyy10. start_med $ next_med $; format start next yymmdd10.; /* Change format to yymmdd10. */ datalines; 1,10/10/2006,09/09/2007,insulin,OAD 1,09/09/2007,10/10/2007,OAD,OAD 1,10/10/2007,16/01/2008,OAD,OAD 1,16/01/2008,06/08/2009,OAD,insulin 1,06/08/2009,30/08/2009,insulin,insulin 2,10/10/2006,09/09/2007,insulin,OAD 2,09/09/2007,10/10/2007,OAD,OAD 2,10/10/2007,16/01/2008,OAD,OAD 2,16/01/2008,19/01/2008,OAD,OAD 2,19/01/2008,06/08/2009,OAD,insulin 2,06/08/2009,30/08/2009,insulin,insulin ; run;
For each id, I want to merge their date variables if start_med=end_med=end_med in next row. In this example, the desired dataset should be:
data medication1; infile datalines dsd truncover; input id $ start : ddmmyy10. next : ddmmyy10. start_med $ next_med $; format start next yymmdd10.; /* Change format to yymmdd10. */ datalines; 1,10/10/2006,09/09/2007,insulin,OAD 1,09/09/2007,16/01/2008,OAD,OAD 1,16/01/2008,06/08/2009,OAD,insulin 1,06/08/2009,30/08/2009,insulin,insulin 2,10/10/2006,09/09/2007,insulin,OAD 2,09/09/2007,19/01/2008,OAD,OAD 2,19/01/2008,06/08/2009,OAD,insulin 2,06/08/2009,30/08/2009,insulin,insulin ; run;
... View more