DATA Step, Macro, Functions and more

How to compare a datetime field?

Reply
Contributor
Posts: 40

How to compare a datetime field?

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.

Occasional Contributor
Posts: 10

How to compare a datetime field?

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

Contributor
Posts: 29

How to compare a datetime field?

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;

Ask a Question
Discussion stats
  • 2 replies
  • 250 views
  • 0 likes
  • 3 in conversation