data a;
input patientid start1_date : mmddyy10. end1_date : mmddyy10. start2 : mmddyy10. end2 : mmddyy10. ;
format start1_date end1_date start2 end2 mmddyy10.;
datalines;
1 5/5/2009 6/6/2009 1/1/2006 2/2/2006
1 5/5/2009 6/6/2009 2/2/2007 3/2/2007
1 5/5/2009 6/6/2009 5/1/2009 6/1/2009
1 5/5/2009 6/6/2009 7/7/2009 12/1/2009;
run;
I have the above data. I am trying to create a subset that includes all periods for (start2-end2) that overlap with any of the intervals from (start1_date- end1_date). No requirement for a minimum overlap in days.
Required output for this data
1 5/5/2009 6/6/2009 5/1/2009 6/1/2009
Hello,
I propose this solution:
data a;
input patientid start1_date : mmddyy10. end1_date : mmddyy10. start2 : mmddyy10. end2 : mmddyy10. ;
format start1_date end1_date start2 end2 mmddyy10.;
datalines;
1 5/5/2009 6/6/2009 1/1/2006 2/2/2006
1 5/5/2009 6/6/2009 2/2/2007 3/2/2007
1 5/5/2009 6/6/2009 5/1/2009 6/1/2009
1 5/5/2009 6/6/2009 7/7/2009 12/1/2009
;
run;
data b;
do until (last.patientid);
set a;
by patientid;
if intnx('month',start1_date,0,"BEGINNING")=intnx('month',start2,0,"BEGINNING")
and
intnx('month',end1_date,0,"BEGINNING")=intnx('month',end2,0,"BEGINNING")
then output;
end;
run;
Hi @lillymaginta While I always enjoyed attempting to solve your questions, this one is not quite clear. I m wary of my understanding of the requirement.
Anyways:
data a;
input patientid start1_date : mmddyy10. end1_date : mmddyy10. start2 : mmddyy10. end2 : mmddyy10. ;
format start1_date end1_date start2 end2 mmddyy10.;
datalines;
1 5/5/2009 6/6/2009 1/1/2006 2/2/2006
1 5/5/2009 6/6/2009 2/2/2007 3/2/2007
1 5/5/2009 6/6/2009 5/1/2009 6/1/2009
1 5/5/2009 6/6/2009 7/7/2009 12/1/2009
;
run;
proc sql;
create table want(drop=x:) as
select *,abs (start2-start1_date) as x1,abs(end2-end1_date) as x2
from a
group by patientid
having min(abs (start2-start1_date))=x1 and min(abs(end2-end1_date))=x2
order by patientid,start2,end2;
quit;
Hello,
I propose this solution:
data a;
input patientid start1_date : mmddyy10. end1_date : mmddyy10. start2 : mmddyy10. end2 : mmddyy10. ;
format start1_date end1_date start2 end2 mmddyy10.;
datalines;
1 5/5/2009 6/6/2009 1/1/2006 2/2/2006
1 5/5/2009 6/6/2009 2/2/2007 3/2/2007
1 5/5/2009 6/6/2009 5/1/2009 6/1/2009
1 5/5/2009 6/6/2009 7/7/2009 12/1/2009
;
run;
data b;
do until (last.patientid);
set a;
by patientid;
if intnx('month',start1_date,0,"BEGINNING")=intnx('month',start2,0,"BEGINNING")
and
intnx('month',end1_date,0,"BEGINNING")=intnx('month',end2,0,"BEGINNING")
then output;
end;
run;
Hi novinosrin, I appreciate the response and apologize for not being clear. I wanted to retain all intervals from start2-end2 that overlap with the intervals from start1-end1 even if the overlap was one day.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.