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.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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