DATA Step, Macro, Functions and more

Problem using yymmdd11. informat

Accepted Solution Solved
Reply
Contributor
Posts: 51
Accepted Solution

Problem using yymmdd11. informat

Hi

I have a text variable containg dates in the format:

YYYY-MMM-DD

2011-FEB-14

2002-SEP-22

etc

I'm trying to convert these to SAS dates using input statement but get invalid data message for the INPUT statement

Any help on how to get this working

eg

data test;

    date1='2011-AUG-12';

    date2=input(date1,yymmdd11.);

run;

Thanks
Steve


Accepted Solutions
Solution
‎12-09-2011 01:07 PM
Trusted Advisor
Posts: 1,300

Problem using yymmdd11. informat


All Replies
SAS Super FREQ
Posts: 683

Problem using yymmdd11. informat

Hi Steve

I do not know of a format, but you can write a function to make a SAS date value out of the string, see sample below:

proc fcmp outlib=work.myFunctions.dates;
  function xDate( date $);
    length dlm $ 1;
    dlm =
"-";
    year = scan(date,
1, dlm);
    month = scan(date, 2, dlm);
    day = scan(date, 3, dlm);
    newDate = cats(day, month, year);
    newDate_N = input(newDate,
date9.);
    return(newDate_N);
  endsub;
run;


options
 
cmplib=(work.myFunctions)
;


data testFunction;
  date1 = '2011-AUG-12';
  date2 = xDate(date1);
 
format date2 date9.;
run;

Bruno

Occasional Contributor
Posts: 8

Re: Problem using yymmdd11. informat

How about:

data test;   

      date1='2011-AUG-12';    

     date2=input(substr(date1,10,2)||substr(date1,6,3)||substr(date1,1,4),date9.);

     put date1= date2= ;

run;

Solution
‎12-09-2011 01:07 PM
Trusted Advisor
Posts: 1,300

Problem using yymmdd11. informat

anydtdte11.

Super Contributor
Posts: 1,636

Problem using yymmdd11. informat

data test;

    date1='2011-AUG-12';

    date2=input(date1,anydtdte11.);

          format date2 mmddyy10.;

run;

proc print;run;

Contributor
Posts: 51

Problem using yymmdd11. informat

Thanks - does the job!...now to read up on it......

PROC Star
Posts: 7,363

Problem using yymmdd11. informat

Not a lot to look up on it (http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002605538.htm), but the anydtdte informat appears to be able to read dates that give all of the other date informats problems.  A useful system option to supplement it is the:

options datestyle=mdy

in order to guide the informat regarding the order of the three date parts.

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 435 views
  • 4 likes
  • 6 in conversation