Question about informat:

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Question about informat:

Hello everyone. this is likely to be a very stupid question, but I cannot figure out how to solve this.

Basically I have files which have dates in the format like this:  01 October 2013,  25 June 2011 etc.

I have tried to import it in with varies informats but none are working...

I have also thought of importing it as string and then substr the D M Y out but it is infeasible due to the inconsistency of the length of months, please could anyone give me a hand on this?

 

Thanks so much!

William


Accepted Solutions
Solution
‎02-20-2014 12:20 PM
Occasional Contributor
Posts: 7

Re: Question about informat:

Try the informat  ANYDTDTE20.  

My Example:

data _null_;

       infile cards;

       input dte ANYDTDTE20.;

       put dte= date9.;

cards;

01 October 2013

;;;;

run;

The log outputs:
dte=01OCT2013

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

View solution in original post


All Replies
Super User
Posts: 17,840

Re: Question about informat:

My two tries, the second worked. Probably not efficient or fancy, but it works Smiley Happy

data have;

var1="01 October 2013"; output;

var1="25 June 2011"; output;

run;

data want;

    set have;

    test1=input(compress(var1), anydtdte.);

    temp=scan(var1,1)||substr(scan(var1, 2), 1,3)||scan(var1, 3);

    test3=input(temp, anydtdte.);

    format test: date9.;

run;

Respected Advisor
Posts: 4,651

Re: Question about informat:

You can try this:

options locale=English_UnitedKingdom;

data _null_;

var1="01 October 2013";

d = input(var1, nldate20.);

put d :date9.;

var1="25 June 2011";

d = input(var1, nldate20.);

put d :date9.;

run;

PG

PG
Contributor
Posts: 33

Re: Question about informat:

There's a dirty way, as always

Something like this.

date_new=(upcase(compress(substr(date,1,7)||substr(data,length(date)-3)),date9.)))

I've write it by memory. The concept is: take the first 7 char ('01 oct') and the last 4 (2013), concanete them , compress them, upcase then and you get

01OCT2013

Use the informat date9.

And you get the date

Very dirty

Solution
‎02-20-2014 12:20 PM
Occasional Contributor
Posts: 7

Re: Question about informat:

Try the informat  ANYDTDTE20.  

My Example:

data _null_;

       infile cards;

       input dte ANYDTDTE20.;

       put dte= date9.;

cards;

01 October 2013

;;;;

run;

The log outputs:
dte=01OCT2013

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

N/A
Posts: 1

Re: Question about informat:

Try using the informat:worddatx.

Thank You

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 389 views
  • 6 likes
  • 6 in conversation