BookmarkSubscribeRSS Feed
My_SAS
Calcite | Level 5

23june2012 11:12:34:45

I am ahving a char variable i want the date time with nano secs in one variable and date in another variable


output

date                                  time
23june2012                11:12:34:45

7 REPLIES 7
My_SAS
Calcite | Level 5

sorry the data is like this with nano seconds also

2012-07-11 09:43:20:45

output

date                       time

2012-07-11              09:43:20:45

shivas
Pyrite | Level 9

Hi,

Try this...

data have;

input date ymddttm24.;

dt=datepart(date);

tm=timepart(date);

format dt date9.;

format tm time12.2;

cards;

2012-07-11 09:43:20.45

;

run;

Thanks,

Shiva

My_SAS
Calcite | Level 5

Antoher Req

2012-07-11 09:43:20.52

in this i want the time till sec but it was rounding off

output shd be 09:43:20

but converting to 09:43:21

shivas
Pyrite | Level 9

Hi,

See the output I am getting it is not rounding off...after running the same code(sas 9.2 version)

Bsas.png

Thanks,

Shiva

My_SAS
Calcite | Level 5

SORY I AM SAYING ABOUT SECONDS NOT MILL SECONDS ACTUALLY I WANT UP TO SECONDS NOT MILLI SECONDS AS IT WAS ROUNDING MY LAST MILLI SECOND TO SEC

09:43:20.52

I WANT THE OUTPUT BE   09:43:20

BUT IT WAS CONVERTING TO  09:43:21

PL HELP ME IN THIS

shivas
Pyrite | Level 9

Hi,

Try this..

data have;

input date ymddttm.;

dt=datepart(date);

tm=timepart(date);

format dt date9.;

format tm time8.2;

cards;

2012-07-11 09:43:20.45

2012-07-11 09:53:20.52

;

run;

Ksharp
Super User

Or truncate it firstly.

data have;
input char_date & $40.;
date=input(substrn(char_date,1,findc(char_date,'.')-1), ymddttm.);
dt=datepart(date);
tm=timepart(date);
format  dt date9. date datetime.;
format tm time.;
cards;
2012-07-11 09:43:20.45
2012-07-11 09:53:20.52
;

run;

Ksharp

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