DATA Step, Macro, Functions and more

Selecting the Id at least 10 days before or after the actual date

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

Selecting the Id at least 10 days before or after the actual date

Hello everyone,

 

I have a following sample dataset with three different date variables. Below is just a sample dataset. I want to select Ids which are at least 10 days before or after the actual date. For example if my date is 06/30/2014, I want to select the IDs which have a difference of 10 days before enddate and 10 days after start date. The date variable is in a different format than the start date and end date. Could you guide me how to do this. Thank you

 

 

 

dateidstartend
6/30/201411974720088
7/1/201421984420057
7/2/201431899320088
7/3/201441974720088
5/12/201451984420057

Accepted Solutions
Solution
‎05-19-2016 02:26 PM
Super User
Posts: 19,822

Re: Selecting the Id at least 10 days before or after the actual date

Posted in reply to danwarags

Create your maximum interval by subtracting 10 from start date and adding 10 to end date and comparing that to your date. 

 

If (start-10) <= date <= (end + 10);

View solution in original post


All Replies
Super User
Posts: 19,822

Re: Selecting the Id at least 10 days before or after the actual date

Posted in reply to danwarags

Ok.. which date is which? How do the start and end dates come into play? WHen you say within 10 days are you intending to use start/end date or date values from other observations?

 

You can make the start and end dates look like the others by using a format. 

 

format start end date9.;

 

Is the first date a SAS date or is it a character variable?

 

Please also include your expected output. 

Contributor
Posts: 44

Re: Selecting the Id at least 10 days before or after the actual date

Hello Reeza,

 

Thanks for quick replay. Sorry for the confusion. For more clarity I formatted the dataset as below. For example, in the below example, the bolded observations satisfies the criteria. For the second ID, the difference between the actual date and start date is less than 10 days and the difference betwen the actual date and end date is also 10 days. Same thing with the third ID. But the other observations are way far from the actual dates. So, I want to select ID 2 and 3. 

 

 

Actual dateidstart dateend date
06/30/2014101/24/201412/31/2014
07/1/2014206/28/201407/07/2014
07/2/2014306/30/201407/08/2014
07/3/2014405/05/201409/04/2014
05/12/2014505/10/201406/12/2014

 

Thank you

Solution
‎05-19-2016 02:26 PM
Super User
Posts: 19,822

Re: Selecting the Id at least 10 days before or after the actual date

Posted in reply to danwarags

Create your maximum interval by subtracting 10 from start date and adding 10 to end date and comparing that to your date. 

 

If (start-10) <= date <= (end + 10);
Super User
Posts: 5,432

Re: Selecting the Id at least 10 days before or after the actual date

Posted in reply to danwarags
Actually I think you need a compound criteria if I interpret the description right:

Where date between start -10 and start+10 and
Date between end-10 and end+10;
Data never sleeps
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 291 views
  • 2 likes
  • 3 in conversation