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
date | id | start | end |
6/30/2014 | 1 | 19747 | 20088 |
7/1/2014 | 2 | 19844 | 20057 |
7/2/2014 | 3 | 18993 | 20088 |
7/3/2014 | 4 | 19747 | 20088 |
5/12/2014 | 5 | 19844 | 20057 |
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);
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.
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 date | id | start date | end date |
06/30/2014 | 1 | 01/24/2014 | 12/31/2014 |
07/1/2014 | 2 | 06/28/2014 | 07/07/2014 |
07/2/2014 | 3 | 06/30/2014 | 07/08/2014 |
07/3/2014 | 4 | 05/05/2014 | 09/04/2014 |
05/12/2014 | 5 | 05/10/2014 | 06/12/2014 |
Thank you
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);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.