Desktop productivity for business analysts and programmers

How to import datetime ddmmyyyy hh:mm:ss informat

Reply
SAS Employee
Posts: 2

How to import datetime ddmmyyyy hh:mm:ss informat

Hello,

I'm trying to import a txt file with 3 datetime fields. The fields are ddmmyyyy hh:mm:ss and I can't find the informat corresponding to this one. I've tried with anydt but doesn't work.

Some fields are imported missing and many others wrong. For example 01/12/2012 09:24:54 is imported as 12Jan12 when it should be 1Dec...

Any suggestions?

thanks in advance.

Luciana

Super Contributor
Posts: 339

Re: How to import datetime ddmmyyyy hh:mm:ss informat

If anydt does read the value but fails to properly distinguish months from days, it likely has to do with your

DATESTYLE=

option. However, anydt. may or may not work with all datetime informats. Try

options DATESTYLE=dmy;

before your data step and see if it fixes your issue.

Vincent

Super Contributor
Posts: 339

Re: How to import datetime ddmmyyyy hh:mm:ss informat

options datestyle=dmy;

data have2;

input v1 anydtdtm.;

put v1 datetime18.;

datalines;

01/12/2012 09:24:54

;

run;

output to log is

01DEC2012:09:24:54

So it should solve your problem.

Vince

SAS Employee
Posts: 2

Re: How to import datetime ddmmyyyy hh:mm:ss informat

Thanks Vince.

I was trying to avoid a program task and use the import node, but I guess it's not going to be possible.

Super Contributor
Posts: 339

Re: How to import datetime ddmmyyyy hh:mm:ss informat

Hrm I'm not too familiar with what all options can be played directly with EG interface but here's an alternative that should allow you to only set the option and use the import interface as you did before

options ->custom code->insert custom sas code before task and query code (Check) -> edit...

type in a single line

options datestyle=dmy;

Save and then run whatever you were running.

Ask a Question
Discussion stats
  • 4 replies
  • 4926 views
  • 1 like
  • 2 in conversation