I am trying to find to retain the value of 1 if a specific date (dg_date) occurred within an interval and 0 otherwise. The interval start and end date are presented with the variables, start and end.
data a;
input patientid dg_date : mmddyy10. start : mmddyy10. send : mmddyy10. ;
format dg_date start end mmddyy10.;
datalines;1 5/5/2009 1/1/2006 2/2/2006
1 5/5/2009 2/2/2007 3/2/2007
1 5/5/2009 5/1/2009 6/1/2009
1 5/5/2009 7/7/2009 12/1/2009
2 1/2/2007 1/2/2006 12/2/2006
2 1/2/2007 12/31/2006 5/5/2007
2 1/2/2007 6/6/2007 7/7/2007;
run;
Output
patientid outcome
1 0
1 0
1 1
1 0
2 0
2 1
2 0
data want;
set a;
if start < dg_date < send then flag=1;
else flag=0;
run;
@lillymaginta wrote:
I am trying to find to retain the value of 1 if a specific date (dg_date) occurred within an interval and 0 otherwise. The interval start and end date are presented with the variables, start and end.
data a; input patientid dg_date : mmddyy10. start : mmddyy10. send : mmddyy10. ; format dg_date start end mmddyy10.; datalines;1 5/5/2009 1/1/2006 2/2/2006 1 5/5/2009 2/2/2007 3/2/2007 1 5/5/2009 5/1/2009 6/1/2009 1 5/5/2009 7/7/2009 12/1/2009 2 1/2/2007 1/2/2006 12/2/2006 2 1/2/2007 12/31/2006 5/5/2007 2 1/2/2007 6/6/2007 7/7/2007; run;Output patientid outcome 1 0 1 0 1 1 1 0 2 0 2 1 2 0
data want;
set a;
if start < dg_date < send then flag=1;
else flag=0;
run;
@lillymaginta wrote:
I am trying to find to retain the value of 1 if a specific date (dg_date) occurred within an interval and 0 otherwise. The interval start and end date are presented with the variables, start and end.
data a; input patientid dg_date : mmddyy10. start : mmddyy10. send : mmddyy10. ; format dg_date start end mmddyy10.; datalines;1 5/5/2009 1/1/2006 2/2/2006 1 5/5/2009 2/2/2007 3/2/2007 1 5/5/2009 5/1/2009 6/1/2009 1 5/5/2009 7/7/2009 12/1/2009 2 1/2/2007 1/2/2006 12/2/2006 2 1/2/2007 12/31/2006 5/5/2007 2 1/2/2007 6/6/2007 7/7/2007; run;Output patientid outcome 1 0 1 0 1 1 1 0 2 0 2 1 2 0
Thank you for the prompt response!
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.