BookmarkSubscribeRSS Feed
sasbasls
Calcite | Level 5

Hello,

I need to compare a datetime field if it is b/w particular hours ? For Ex: if time in datetime field falls b/w 2 intervals of time (b/w 2 PM - 5 PM etc)

Would any one please let me know. I was using put function and comparing against integers.

thanks in advance.

2 REPLIES 2
Gerd47
Calcite | Level 5

You can use the timepart funtion for this task, for example:

data test;

datim1=500000000;

datim2=500005000;

datimt=500004000;

output;

datimt=500009000;

output;

format datim1 datimt datim2 datetime.;

run;

data test;

set test;

where timepart(datimt) between timepart(datim1) and timepart(datim2);

run;

Best regards,

Gerd

varunnakra
Fluorite | Level 6

Hi, yes we can use the Timepart function for the same

Data DateTimeExtract;

Set OriginalDateTime;

  

   TimeForDate = Timepart(DateField);

   If ’14:00:00’t le TimeForDate le ’17:00:00’t;

Run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1451 views
  • 1 like
  • 3 in conversation