DATA Step, Macro, Functions and more

Date range by Year

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

Date range by Year

Hello Everyone,

 

I have a dataset with datevalues as shown below. I am trying to filter the dates which fall in certain range. How should I code this. For example, for the below dataset I need the date values in between 2001-01-01 and 2004-12-31. 

 

DateID
2000-12-28 1
2001-05-26
2002-06-12
1999-05-25 
2001-01-05 
2002-01-20 8
1998-05-17 
2007-06-20 
2008-04-26 10 

Accepted Solutions
Solution
‎09-09-2016 04:39 PM
Super User
Posts: 17,840

Re: Date range by Year

If your dates are SAS dates (numeric with a date format) then filtering based on year should be fine.

 

where year(date) between 2000 and 2004;

Or

 

if 2000 <= year(date) <= 2004;

View solution in original post


All Replies
Solution
‎09-09-2016 04:39 PM
Super User
Posts: 17,840

Re: Date range by Year

If your dates are SAS dates (numeric with a date format) then filtering based on year should be fine.

 

where year(date) between 2000 and 2004;

Or

 

if 2000 <= year(date) <= 2004;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 221 views
  • 2 likes
  • 2 in conversation