BookmarkSubscribeRSS Feed
y_fu
Fluorite | Level 6

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?

 

5 REPLIES 5
novinosrin
Tourmaline | Level 20

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);
y_fu
Fluorite | Level 6

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

novinosrin
Tourmaline | Level 20

Aah ok,

 

newvar= input(datetime, datetime20.);

will give you numeric datetime value

Kurt_Bremser
Super User

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

ballardw
Super User

@y_fu wrote:

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


Seconds from when?

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 983 views
  • 0 likes
  • 4 in conversation