This widget could not be displayed.
This widget could not be displayed.
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

Good afternoon,

 

I have a column within my dataset called "file_accepted". A sample record shows as "09MAR2007:16:12:21". 

 

I am trying to create a field that grabs the 2 digits after the first colon, in this example the 16... which is military time for 4pm. Ideally, I would like my new field to be coded as "1" if the time is at 4PM or after, and "0" if the time is before 4PM. 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

What type of variable, character or numeric? If the variable is a SAS datetime value, numeric with a format of DATETIME18 or similar then you can check the Hour of the value with the hour function:

 

data want;

   set have;

   newvar = (Hour(file_accepted) ge 16);

run;

 

If it isn't a datetime value then you really should make a datetime valued version as most of the steps involving comparisons, selections or other manipulations of datetimes start with that conversion.

View solution in original post

3 REPLIES 3
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

What type of variable, character or numeric? If the variable is a SAS datetime value, numeric with a format of DATETIME18 or similar then you can check the Hour of the value with the hour function:

 

data want;

   set have;

   newvar = (Hour(file_accepted) ge 16);

run;

 

If it isn't a datetime value then you really should make a datetime valued version as most of the steps involving comparisons, selections or other manipulations of datetimes start with that conversion.

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
That did it! Thank you!!!
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
What's your data type and format on that column?

If it's a datetime you can likely use the HOUR() function.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1775 views
  • 1 like
  • 3 in conversation
This widget could not be displayed.
This widget could not be displayed.