BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

Hello Experts,

My Date_1 < Date_2 so I would like to get only the observation with 7 days diffrence. Could you tell me if my code is right :

proc sql;
	create table Result as select a.*, b.* from total_RE as a
		left join SUP as b on a.pers=b.pers
			and intck('day',b.D_1, a.D_2)<7;
quit;

Thank you !

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Exactly 7 days?  7 days or less?  Or less than 7 days?

Assuming your date variables have DATE values then they are already stored as a number of days, so there is no need to use any special functions to check the differences.

 

To test if D2 is between D1 and up to 7 days after D1 just use:

proc sql;
create table Result as 
  select a.*, b.* 
  from total_RE as a
  left join SUP as b
    on a.pers=b.pers
   and a.D_2 between b.D_1 and b.D_1+7
;
quit;

If you actually have DATETIME values then you would need to use INTNX() or INTCK() since those values are stored as number of seconds.  But you would need to use the DTDATE interval and not the DATE interval.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@SASdevAnneMarie wrote:

 

My Date_1 < Date_2 so I would like to get only the observation with 7 days diffrence. Could you tell me if my code is right :


Did you actually try running this code? SAS will tell you if the code is right, and do so more quickly and more authoritatively than anyone here can do (especially since we don't have your data).

 

There do not appear to me to be any syntax errors (but again SAS will give you are more authoritative answer). I question the logic in the code which doesn't seem to match the words you used; 7 days difference would be 

 

intck('day',b.D_1, a.D_2)=7

 

--
Paige Miller
Tom
Super User Tom
Super User

Exactly 7 days?  7 days or less?  Or less than 7 days?

Assuming your date variables have DATE values then they are already stored as a number of days, so there is no need to use any special functions to check the differences.

 

To test if D2 is between D1 and up to 7 days after D1 just use:

proc sql;
create table Result as 
  select a.*, b.* 
  from total_RE as a
  left join SUP as b
    on a.pers=b.pers
   and a.D_2 between b.D_1 and b.D_1+7
;
quit;

If you actually have DATETIME values then you would need to use INTNX() or INTCK() since those values are stored as number of seconds.  But you would need to use the DTDATE interval and not the DATE interval.

SASdevAnneMarie
Barite | Level 11
Thank you very much!
I have datetime values and I would like to chose 7 days or less interval. How to indicate the datetime interval please?

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
  • 5 replies
  • 654 views
  • 1 like
  • 4 in conversation