I wrote this code , but it doesnt seem to work completely : data want ; set have ; by PatientID ; StartDate2 = StartDate ; retain StartDate2 ; format new_enddate new_startdate StartDate2 mmddyy10. ; if (EndDate - StartDate) ge 180 then do ; new_startdate = StartDate2 ; new_enddate = sum(new_startdate,180); StartDate2 = StartDate +181 ; end; else if (EndDate - StartDate2) lt 180 then do; new_enddate = sum(StartDate2,180) ; new_startdate = StartDate2 ; end ; run ; RAW DATA Obs PatientID LineName StartDate EndDate1234567891011121314151617181920 F000678A98792 Gemcitabine,Paclitaxel Protein-Bound 02/01/2016 02/11/2016 F002F4C07392F FOLFIRINOX 08/19/2015 04/05/2016 F002F4C07392F Gemcitabine,Paclitaxel Protein-Bound 04/06/2016 05/11/2016 F00314B361B6A Gemcitabine 10/12/2015 11/27/2016 F00314B361B6A Gemcitabine,Paclitaxel Protein-Bound 11/28/2016 08/21/2017 F00314B361B6A FOLFOX 08/22/2017 03/07/2018 F003E7ADEB2F8 Gemcitabine,Paclitaxel Protein-Bound 01/20/2017 02/03/2017 F006A77E4CDB0 FOLFIRINOX 07/12/2017 08/27/2017 F006A77E4CDB0 Pembrolizumab 08/28/2017 12/07/2017 F007499692F0D FOLFIRINOX 08/28/2017 10/31/2017 F007499692F0D Gemcitabine,Paclitaxel Protein-Bound 11/01/2017 03/26/2018 F0080CAE5E872 Gemcitabine,Paclitaxel Protein-Bound 02/12/2014 04/19/2017 F00C081DC6BC4 Gemcitabine,Paclitaxel Protein-Bound 02/17/2017 08/13/2017 F00C081DC6BC4 Capecitabine,Gemcitabine 08/14/2017 11/09/2017 F00CC20661EE3 Gemcitabine,Paclitaxel Protein-Bound 10/19/2015 05/03/2016 F00CC20661EE3 FOLFIRINOX 05/04/2016 05/09/2016 F00E0ED1D3143 FOLFIRINOX 09/21/2016 01/02/2017 F00E0ED1D3143 Fluorouracil,Gemcitabine,Irinotecan,Leucovorin,Oxaliplatin,Paclitaxel Protein-Bound 01/03/2017 03/27/2018 F00F92CD2DB8C FOLFOX 06/09/2016 06/23/2016 F01147636BCCA Gemcitabine,Paclitaxel Protein-Bound 08/04/2015 11/03/2015 EPISODE RULE I want to see the values in StartDate2 to appear in new_startdate .. and tehn add 180 to them to get the new_enddate.. Obs PatientID LineName StartDate EndDate new_startdate new_enddate StartDate21234567891011121314151617181920 F000678A98792 Gemcitabine,Paclitaxel Protein-Bound 02/01/2016 02/11/2016 02/01/2016 07/30/2016 02/01/2016 F002F4C07392F FOLFIRINOX 08/19/2015 04/05/2016 02/16/2016 02/15/2016 08/19/2015 F002F4C07392F Gemcitabine,Paclitaxel Protein-Bound 04/06/2016 05/11/2016 04/06/2016 10/03/2016 04/06/2016 F00314B361B6A Gemcitabine 10/12/2015 11/27/2016 04/10/2016 04/09/2016 10/12/2015 F00314B361B6A Gemcitabine,Paclitaxel Protein-Bound 11/28/2016 08/21/2017 05/28/2017 05/27/2017 11/28/2016 F00314B361B6A FOLFOX 08/22/2017 03/07/2018 02/19/2018 02/18/2018 08/22/2017 F003E7ADEB2F8 Gemcitabine,Paclitaxel Protein-Bound 01/20/2017 02/03/2017 01/20/2017 07/19/2017 01/20/2017 F006A77E4CDB0 FOLFIRINOX 07/12/2017 08/27/2017 07/12/2017 01/08/2018 07/12/2017 F006A77E4CDB0 Pembrolizumab 08/28/2017 12/07/2017 08/28/2017 02/24/2018 08/28/2017 F007499692F0D FOLFIRINOX 08/28/2017 10/31/2017 08/28/2017 02/24/2018 08/28/2017 F007499692F0D Gemcitabine,Paclitaxel Protein-Bound 11/01/2017 03/26/2018 11/01/2017 04/30/2018 11/01/2017 F0080CAE5E872 Gemcitabine,Paclitaxel Protein-Bound 02/12/2014 04/19/2017 08/12/2014 08/11/2014 02/12/2014 F00C081DC6BC4 Gemcitabine,Paclitaxel Protein-Bound 02/17/2017 08/13/2017 02/17/2017 08/16/2017 02/17/2017 F00C081DC6BC4 Capecitabine,Gemcitabine 08/14/2017 11/09/2017 08/14/2017 02/10/2018 08/14/2017 F00CC20661EE3 Gemcitabine,Paclitaxel Protein-Bound 10/19/2015 05/03/2016 04/17/2016 04/16/2016 10/19/2015 F00CC20661EE3 FOLFIRINOX 05/04/2016 05/09/2016 05/04/2016 10/31/2016 05/04/2016 F00E0ED1D3143 FOLFIRINOX 09/21/2016 01/02/2017 09/21/2016 03/20/2017 09/21/2016 F00E0ED1D3143 Fluorouracil,Gemcitabine,Irinotecan,Leucovorin,Oxaliplatin,Paclitaxel Protein-Bound 01/03/2017 03/27/2018 07/03/2017 07/02/2017 01/03/2017 F00F92CD2DB8C FOLFOX 06/09/2016 06/23/2016 06/09/2016 12/06/2016 06/09/2016 F01147636BCCA Gemcitabine,Paclitaxel Protein-Bound 08/04/2015 11/03/2015 08/04/2015 01/31/2016 08/04/2015 I want it to look like this : obs Patient ID LineName StartDate EndDate 1 F000678A98792 Gemcitabine,Paclitaxel Protein-Bound 2/1/2016 7/1/2016 2 F002F4C07392F FOLFIRINOX 8/19/2015 1/19/2016 3 F002F4C07392F FOLFIRINOX 1/20/2016 6/20/2016 4 F002F4C07392F Gemcitabine,Paclitaxel Protein-Bound 4/6/2016 5/11/2016 5 F00314B361B6A FOLFOX 8/22/2017 1/22/2017 6 F00314B361B6A FOLFOX 1/23/2017 3/7/2018 7 F00314B361B6A Gemcitabine 10/12/2015 3/12/2016 8 F00314B361B6A Gemcitabine 3/13/2016 8/13/2016 9 F00314B361B6A Gemcitabine 8/14/2016 11/27/2016 10 F00314B361B6A Gemcitabine,Paclitaxel Protein-Bound 11/28/2016 4/28/2016 11 F00314B361B6A Gemcitabine,Paclitaxel Protein-Bound 4/29/2016 9/29/2016 12 F00314B361B6A Gemcitabine,Paclitaxel Protein-Bound 9/30/2016 3/2/2017 13 F00314B361B6A Gemcitabine,Paclitaxel Protein-Bound 3/3/2016 8/3/2017 14 F00314B361B6A Gemcitabine,Paclitaxel Protein-Bound 8/4/2017 8/21/2017
... View more