BookmarkSubscribeRSS Feed
KristianDagless
Calcite | Level 5

Hi All,

 

I have a data set and I need to filter based on a specific time from a datetime variable.

 

For example:

 

'11MAR2019:13:02:30 '

 

I'd like to filter on all results post 5PM on the above variable, I'm new to SAS. I understand a timepart may be suitable here but I am unable to produce the results I require using this function. 

 

Many thanks in advance for your assistance.

2 REPLIES 2
Kurt_Bremser
Super User

Please show your code and log, and some example data (in usable form - a data step with datalines), so we have material for diagnosis.

 

Your mention of the timepart() function is correct, though:

data have;
input dtval e8601dt19.;
format dtval e8601dt19.;
cards;
2019-03-20T08:00:00
2019-03-20T17:05:00
;
run;

data want;
set have;
where timepart(dtval) > '17:00:00't;
run;

proc print data=want noobs;
run;

Result:

dtval

2019-03-20T17:05:00

Only the later of the two observations is selected.

ballardw
Super User

Or use one of the time extraction functions:

 

data want;
   set have;
   where hour(dtval) ge 17;
run; 

for example. I wasn't sure if you wanted strictly greater than or greater than or equal so used the later.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2934 views
  • 0 likes
  • 3 in conversation