DATA Step, Macro, Functions and more

How to read yyyymmddhmmss informat

Accepted Solution Solved
Reply
Contributor
Posts: 73
Accepted Solution

How to read yyyymmddhmmss informat

Hello Expert,

 

Could you Please help me to read yyyymmddhmmss date value.

 

I have a character column  which is containing records in yyyymmddhmmss format.

 

Please help me to read values.

 

Data Test;

Length A $60.;

A='20180205092045';

B=input(A,informat);

run;

 

 

Please let me which Informat can read it properly.

 

 

Regards,

Ritesh


Accepted Solutions
Solution
‎02-08-2018 06:39 AM
PROC Star
Posts: 499

Re: How to read yyyymmddhmmss informat

Posted in reply to Ritesh_dellvostro

something like 

Data Test;
    A='20180205092045';
    B=input(A, B8601DJ16.);
    format B datetime20.;
run;

View solution in original post


All Replies
Moderator
Posts: 310

Re: How to read yyyymmddhmmss informat

Posted in reply to Ritesh_dellvostro
Data Test;

    Length A $60.;

    A='20180205092045';

    B=input(A,anydtdtm.);

run;
Contributor
Posts: 73

Re: How to read yyyymmddhmmss informat

Posted in reply to AndrewHowell
its not reading in anydtdtm. informat.
I want my data in datetime20.6 format.
Solution
‎02-08-2018 06:39 AM
PROC Star
Posts: 499

Re: How to read yyyymmddhmmss informat

Posted in reply to Ritesh_dellvostro

something like 

Data Test;
    A='20180205092045';
    B=input(A, B8601DJ16.);
    format B datetime20.;
run;
Contributor
Posts: 73

Re: How to read yyyymmddhmmss informat

Thanks Its working

Contributor
Posts: 37

Re: How to read yyyymmddhmmss informat

Posted in reply to Ritesh_dellvostro

Data Test;

Length A $60.;

A='20180205092045';

B=input(A,anydtdte14.);

run;

Super User
Posts: 9,560

Re: How to read yyyymmddhmmss informat

Posted in reply to Ritesh_dellvostro

I strongly advise against the use of the "any" informats. You just tell SAS to make a guess and create something out of a string that could contain absolute crap, and still end up with a non-missing value (and not even a NOTE!) that later wrecks all your analysis.

Force correct data at every step of your analytic chain, and never let the computer do your thinking for you. See Maxims 31 and 22.

 

Follow @kiranv_'s suggestion for using one of the ISO 8601 formats. I'd even use one for display:

Data Test;
    A='20180205092045';
    B=input(A, B8601DJ16.);
    format B e8601dt19.;
run;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Moderator
Posts: 310

Re: How to read yyyymmddhmmss informat

Posted in reply to KurtBremser
I wouldn't advocate the "any" informats in a critical operational environment. But the need which created the "any" informat highlights that there are inputs where we cannot mandate a consistent date/datetime informat. (That may or may not be the case here.)
Any use of an "any" informat MUST come with the presumption that the date might be incorrectly informatted.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 167 views
  • 4 likes
  • 5 in conversation