BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
danwarags
Obsidian | Level 7

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
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
Reeza
Super User

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. 

danwarags
Obsidian | Level 7

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

Reeza
Super User

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);
LinusH
Tourmaline | Level 20
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 1187 views
  • 2 likes
  • 3 in conversation