BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gil_
Quartz | Level 8
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
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

9 REPLIES 9
ballardw
Super User

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;
Gil_
Quartz | Level 8
Hi I need to remove them
ballardw
Super User

@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;
Gil_
Quartz | Level 8
In the log it shows the sec removed but when I open table x=1807660800. How can I show datetime20?
ChrisNZ
Tourmaline | Level 20
data TEST;
   x='05Apr2017:12:15:22'dt;
   x = intnx('minute',x,0,'b');
   format x datetime20.;
   put x=;
run;
Gil_
Quartz | Level 8
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;
ballardw
Super User

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

Gil_
Quartz | Level 8
Ok thanks for assistance
ChrisNZ
Tourmaline | Level 20
You need to use proc sql and an update statement as you replacing in the same table

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 9 replies
  • 10929 views
  • 3 likes
  • 3 in conversation