DATA Step, Macro, Functions and more

datetime conversion

Reply
Occasional Contributor
Posts: 7

datetime conversion

After I import the file, there is a column:

 

Start date

28MAR18:13:00:53
28MAR18:13:01:30
02APR18:14:23:14
02APR18:14:23:14

...

 

I want to calculate a new column to convert the column above to seconds, how can I do that?

 

Super User
Posts: 2,049

Re: datetime conversion

[ Edited ]

Is your datetime variable a numeric one just formatted with datetime format or is it a char?

 

If it is formatted, remove the format , you will see the number of seconds since January 1, 1960.

 

Or if you are looking to extract seconds from the datetime value, use  second function

s=second(datetime);
Occasional Contributor
Posts: 7

Re: datetime conversion

Posted in reply to novinosrin

It is not numeric, it is char. This is the reason I cannot convert them into seconds.

Highlighted
Super User
Posts: 2,049

Re: datetime conversion

[ Edited ]

Aah ok,

 

newvar= input(datetime, datetime20.);

will give you numeric datetime value

Super User
Posts: 10,546

Re: datetime conversion


@y_fu wrote:

It is not numeric, it is char. This is the reason I cannot convert them into seconds.


Still better: use the datetime18. informat when reading the external file..

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,913

Re: datetime conversion


@y_fu wrote:

It is not numeric, it is char. This is the reason I cannot convert them into seconds.


Seconds from when?

 

Ask a Question
Discussion stats
  • 5 replies
  • 75 views
  • 0 likes
  • 4 in conversation