DATA Step, Macro, Functions and more

Reg:Time Part

Reply
Contributor
Posts: 37

Reg:Time Part

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

Contributor
Posts: 37

Re: Reg:Time Part

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

Super Contributor
Posts: 349

Re: Reg:Time Part

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

Contributor
Posts: 37

Re: Reg:Time Part

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

Super Contributor
Posts: 349

Re: Reg:Time Part

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

Contributor
Posts: 37

Re: Reg:Time Part

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

Super Contributor
Posts: 349

Re: Reg:Time Part

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;

Super User
Posts: 9,676

Re: Reg:Time Part

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

Ask a Question
Discussion stats
  • 7 replies
  • 283 views
  • 0 likes
  • 3 in conversation