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

Hello,

 

I am tryin to find how many of the 46 records in the attached file are within 24 hours of each other

 

I have used the code below as one of the conditions?

Can someone please advise if the function is written correctly to capture the cases

	(0 <= INTCK('HOUR', A.ENTRY_DT,N.REG_TM ) <= 24)
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Ranjeeta wrote:

Hello,

 

I am tryin to find how many of the 46 records in the attached file are within 24 hours of each other

 

I have used the code below as one of the conditions?

Can someone please advise if the function is written correctly to capture the cases

	(0 <= INTCK('HOUR', A.ENTRY_DT,N.REG_TM ) <= 24)

You might want

(0 <= abs( INTCK('HOUR', A.ENTRY_DT,N.REG_TM ) ) <= 24)

unless you only want when N.Reg_tm is greater than A.Entry_dt. The Absolute value function make the value positive after the comparison. Or use -24 to 24.

 

You would have to show us the rest of the code to see if you are comparing the records as intended.

 

I would also make very sure that your varaibles are either both TIME only or DATETIME only variables. If one is actually a date time and the other time then you will not get the results that you want. I point this out as we see lots of variables with a name ending in DT that are either date, which SAS has in days as units, or datetime which will have much larger values in general than plain "time of day" variables.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@Ranjeeta wrote:

I am tryin to find how many of the 46 records in the attached file are within 24 hours of each other


I'm afraid this is not well-defined enough to venture an answer. Please explain further and give the desired output. Also, please provide your data according to these instructions and not via Excel files.

--
Paige Miller
Ranjeeta
Pyrite | Level 9
Apologies yes will try to upload clear instructions
Tom
Super User Tom
Super User

Are you going to compare all of the records to each other? Or just compare the two columns in the same record to each other?

Are you doing this in SQL code somehow? If not then why do you have periods in your variable names?

Why not just compare the time difference instead of counting the intervals?

0<= X-Y <= '24:00't
ballardw
Super User

@Ranjeeta wrote:

Hello,

 

I am tryin to find how many of the 46 records in the attached file are within 24 hours of each other

 

I have used the code below as one of the conditions?

Can someone please advise if the function is written correctly to capture the cases

	(0 <= INTCK('HOUR', A.ENTRY_DT,N.REG_TM ) <= 24)

You might want

(0 <= abs( INTCK('HOUR', A.ENTRY_DT,N.REG_TM ) ) <= 24)

unless you only want when N.Reg_tm is greater than A.Entry_dt. The Absolute value function make the value positive after the comparison. Or use -24 to 24.

 

You would have to show us the rest of the code to see if you are comparing the records as intended.

 

I would also make very sure that your varaibles are either both TIME only or DATETIME only variables. If one is actually a date time and the other time then you will not get the results that you want. I point this out as we see lots of variables with a name ending in DT that are either date, which SAS has in days as units, or datetime which will have much larger values in general than plain "time of day" variables.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 822 views
  • 3 likes
  • 4 in conversation