data have;
informat start end mmddyy10.;
format start end date9.;
input id drug start end;
cards;
1 a 1/1/2005 2/17/2005
1 a 2/7/2005 3/3/2005
1 a 3/7/2005 5/5/2005
1 a 5/30/2005 8/9/2005
;run;I want to create a continuous period allowing only 7 days gap between the end date of the period and the start of the next one
output
id start end
1 1/1/2005 5/15/2005
Thank you for the response. I adjusted the dates. I want to allow a gap of 7 days but if there is overlap in the dates such as in the first and the second row (there is an overlap of 10 days) I want to add the 10 days to the end date as refected in the output.
You didn't show multiple ID's, but I presume the dataset is sorted by ID/START, so this program checks for a change in ID:
data have;
informat start end mmddyy10.;
format start end date9.;
input id drug :$1. start end;
cards;
1 a 1/1/2005 2/17/2005
1 a 2/7/2005 3/3/2005
1 a 3/7/2005 5/5/2005
1 a 5/30/2005 8/9/2005
;run;
data want (drop=_:);
set have (keep=id);
by id;
merge have
have (firstobs=2 keep=start rename=(start=_nxtstart));
retain _start;
if first.id or start > lag(end)+7 then _start=start;
if last.id or _nxtstart>end+7;
start=_start;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.