BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10

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 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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 

 




View solution in original post

3 REPLIES 3
Reeza
Super User
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 

 




LinusH
Tourmaline | Level 20
I just an IF that tries the interval?
start <= dg_date <= end
Data never sleeps
lillymaginta
Lapis Lazuli | Level 10

Thank you for the prompt response! 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 740 views
  • 3 likes
  • 3 in conversation