BookmarkSubscribeRSS Feed
SBKH
Calcite | Level 5
In input file have data like this -
2023-09-05-06.15.16.130035
I want to check if this timestamp is less than current timestamp - 14 hours
I am able to get the 14 hours back numeric current timestamp with this code
Data_null_;
File statrep;
/*Get the current timestamp*/;
Current_time = DATETIME();
/* subtract 14 hours (50400 seconds) */
14_hours_ago = current_time -50400;
I need my input file timestamp to change to numeric format so that I can compare these two dates if it's less or greter for my further process.
Or if there any other way to compare dates please let me know
3 REPLIES 3
LinusH
Tourmaline | Level 20

So it's DB2 but you are reading it from a file?

If you access DB2 directly the SAS/ACCESS libname engine maps DB2 timestamps to SAS datetime auotmatically.

if you can't find any suitable existing informat, you can create your own:

SAS Help Center: Syntax: PROC FORMAT PICTURE Statement

Data never sleeps
Patrick
Opal | Level 21

@LinusH wrote:

So it's DB2 but you are reading it from a file?

If you access DB2 directly the SAS/ACCESS libname engine maps DB2 timestamps to SAS datetime auotmatically.

if you can't find any suitable existing informat, you can create your own:

SAS Help Center: Syntax: PROC FORMAT PICTURE Statement


@LinusH 

Agree with your first point. ...plus rounding the floating point number to the 6th decimal.

If reading a string is required: I don't believe a picture FORMAT will help as it's about the need for an INformat.

Patrick
Opal | Level 21

You will need to convert this source string to a pattern for which there is a SAS infomat. Let me know if below conversion is working for you.

data demo;
  input have_string $25.;
  have_string=prxchange('s/^(\d+-\d+-\d+).(\d+).(\d+).(\d+.*)$/$1T$2:$3:$4/oi',1,strip(have_string));
  have_dttm=input(strip(have_string),e8601dt26.6);

  /*Get the current timestamp*/;
  Current_time = DATETIME();

  /* subtract 14 hours (50400 seconds) */
  _14_hours_ago = intnx('dthour',current_time,-14,'s');
  datalines;
2023-09-05-06.15.16.130035
2023-09-05T06:15:16.130035
;

proc print data=demo;
  format have_dttm Current_time _14_hours_ago datetime25.6;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 221 views
  • 0 likes
  • 3 in conversation