BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9
Hello,

I got a data field which looks like 20101222 15:59:57.94

I need to find the dates which are in the last 24 and 48 hours. Can anybody tell me which format to use?

Kind Regards

Filip
3 REPLIES 3
mdavidson
Quartz | Level 8
This will subtract 24 hours from your date field. Change the -24 to whatever you want in order to add/subtract any number of hours from a date time.

intnx('hour', **insert your date field here**, -24);
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
INTNX is the correct function, however argument #1 needs to be "DTHOUR" for a SAS DATETIME variable. If your input data-string is a SAS CHARACTER variable, then you need to convert it to a SAS numeric type DATETIME variable, likely in a DATA step. One way is to split up the string into the DATE and TIME portions, then use the SAS INPUT function in assignment statements to convert each component, and then use a DHMS function to create your SAS DATETIME numeric variable.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

sas datetime variables site:sas.com
Filipvdr
Pyrite | Level 9
Ok thanks, i was on the good way as i had already splitted the datetime into a datepart and timepart. Thanks for the help.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1065 views
  • 0 likes
  • 3 in conversation