BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
P_Y
Calcite | Level 5 P_Y
Calcite | Level 5

What function can I use to change:

 

2014-07-09 11:42:34:826  --> 2014-07-09 11:42:34

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
As Perter.C said, add one more function in it .

Timepart( int( 2014-07-09 11:42:34:826 ) )

View solution in original post

5 REPLIES 5
SASKiwi
PROC Star

Is that value stored in a numeric or character SAS variable? If it is numeric, what format is applied to it?

P_Y
Calcite | Level 5 P_Y
Calcite | Level 5
Is DATETIME22.3 format.
I tried to compute columns by using Timepart(2014-07-09 11:42:34:826) to get the time and in format TIME8, but it round up to 11:42:35. I just want to round down to 11:42:34:000.
Ksharp
Super User
As Perter.C said, add one more function in it .

Timepart( int( 2014-07-09 11:42:34:826 ) )
PeterClemmensen
Tourmaline | Level 20

SAS Datetime values are integers until the milliseconds part. So given that your values are actual numeric datetime values, you can use the Floor or Round Function depending on what you want. 

 

Or you can find an appropriate SAS format if you do not want to change the actual values.

Patrick
Opal | Level 21

SAS datetime values are stored as the count of seconds since 1/1/1960. They are stored in a numerical values, can include fractional seconds and you can use any operator that's suitable for numerical values. 

In your case: If you would want to round to seconds shouldn't the formatted value be 2014-07-09 11:42:35

 

Given your dealing with a numerical variable and depending what you want use either of the following functions:

- round()

- int()

- floor()

- ceil()

These functions area all documented under: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/n01f5qrjoh9h4hn1olbdpb5pr2t... 

One of them will give you exactly what you want.

 

And last but not least: If it's just about printing the internal value without fractional seconds then use DATETIME22. ...but be aware that this will use arithmetic rounding so it will be 35 seconds. 

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
  • 5 replies
  • 396 views
  • 3 likes
  • 5 in conversation