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! 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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