DATA Step, Macro, Functions and more

how to convert character data to datetime

Reply
Occasional Learner
Posts: 1

how to convert character data to datetime

I'm trying to convert the character variable '201803120520' into datetime.

need help. 

 

Thanks

Valued Guide
Posts: 629

Re: how to convert character data to datetime

Check the informats starting with "any", maybe one of them can convert the char-value.

Respected Advisor
Posts: 3,270

Re: how to convert character data to datetime

The ANYDTTME informat should work.

--
Paige Miller
PROC Star
Posts: 629

Re: how to convert character data to datetime

Hi,

You need to do some conversion Like:

data want;
Format Date_Val datetime26.;
Char='201803120520';
Date_Val=INPUT(CATS(SUBSTR(Char,1,8),"T",SUBSTR(Char,9),"00"),B8601DT15.);
run;

 

Thanks,
Suryakiran
Ask a Question
Discussion stats
  • 3 replies
  • 101 views
  • 3 likes
  • 4 in conversation