DATA Step, Macro, Functions and more

How to remove the seconds from datetime20

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 78
Accepted Solution

How to remove the seconds from datetime20

I have a col name create which is a datetime20
The data looks like this 13apr2017:00:00:02
I need the data to look like this
13apr2017:00:00
Thanks for assistance

Accepted Solutions
Solution
‎04-20-2017 06:23 PM
Super User
Posts: 11,343

Re: How to remove the seconds from datetime20

Do you want to actually remove the seconds or just not display them?

 

data junk;
   x='13apr2017:00:00:02'dt;
   y= round(x,60);/* changes the value*/
   put y= datetime20. ;
  /* or just use a different format to suppress display of the seconds*/
   put x= datetime13.; 
run;

View solution in original post


All Replies
Solution
‎04-20-2017 06:23 PM
Super User
Posts: 11,343

Re: How to remove the seconds from datetime20

Do you want to actually remove the seconds or just not display them?

 

data junk;
   x='13apr2017:00:00:02'dt;
   y= round(x,60);/* changes the value*/
   put y= datetime20. ;
  /* or just use a different format to suppress display of the seconds*/
   put x= datetime13.; 
run;
Frequent Contributor
Posts: 78

Re: How to remove the seconds from datetime20

Hi I need to remove them
Super User
Posts: 11,343

Re: How to remove the seconds from datetime20


Gil_ wrote:
Hi I need to remove them

The use the Round in the example. Since datetime values are actually numbers of seconds rounding to the nearest multiple of 60 rounds to the nearest minute.

Of if you want to truncate to the minute regardless of the number of seconds you could use INTNX:

data _null_;
   x='05Apr2017:12:15:22'dt;
   x = intnx('minute',x,0,'b');
   put x datetime20.;
run;
Frequent Contributor
Posts: 78

Re: How to remove the seconds from datetime20

In the log it shows the sec removed but when I open table x=1807660800. How can I show datetime20?
PROC Star
Posts: 1,760

Re: How to remove the seconds from datetime20

data TEST;
   x='05Apr2017:12:15:22'dt;
   x = intnx('minute',x,0,'b');
   format x datetime20.;
   put x=;
run;
Frequent Contributor
Posts: 78

Re: How to remove the seconds from datetime20

I'm getting an error message ... the table is located in a library named Ecms . When I refer the table I get this message
THE ORACLE TABLE CP_EVENT HAS BEEN OPENED FOR OUTPUT. THIS TABLE ALREADY EXISTS
OR THERE IS A NAME CONFLICT WITH AN EXISTING OBJECT. THIS TABLE WILL NOT BE REPLACED . THIS ENGINE DOES NOT SUPPORT REPLACE OPTION

HERE IS THE SCRIPT
DATA ECMS.CP_EVENT;
Set ecms.cp_event;
X=create;
X=intnx ('minute',x,0,'b");
Put x datetime20.
Rum;
Super User
Posts: 11,343

Re: How to remove the seconds from datetime20

Oracle unfortunately uses different behaviors and I don't work with Oracle so can't help there.

Frequent Contributor
Posts: 78

Re: How to remove the seconds from datetime20

Ok thanks for assistance
PROC Star
Posts: 1,760

Re: How to remove the seconds from datetime20

You need to use proc sql and an update statement as you replacing in the same table
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 379 views
  • 3 likes
  • 3 in conversation