BookmarkSubscribeRSS Feed
gauthy
Calcite | Level 5

Hai guys ,

                  I have a requirement , where i have to split time into hours , minutes and seconds .

For example : time is 12 : 40 :12 . I need it as 12 hrs, 40 min and 12 seconds. Kindly give me the syntax for this.

Thanks in advance.

2 REPLIES 2
Steelers_In_DC
Barite | Level 11

Here you go:

data have;

format datetime datetime.;

datetime = today();

run;

data want;

set have;

date = datepart(datetime);

hour = hour(datetime);

min = minute(datetime);

sec = second(datetime);

run;

arodriguez
Lapis Lazuli | Level 10

Hello,

If your data is in character format, you always could use the SCAN function, with ":" as delimiter and select the position that you want

data want;

set have;

format WANT_var $20. hours minutes seconds $2.;

hours=scan(time,1,':');

minutes=scan(time,2,':');

seconds=scan(time,3,':');

WANT_var=hours||" hrs, "||minutes||" min and "||seconds||" seconds;

run;

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
  • 2 replies
  • 1396 views
  • 0 likes
  • 3 in conversation