Saturday 10 February 2018

Character date to numeric date value

I have a variable CPN_DT that is char, length 80 format $80, has following valu

05/21/2010

07/01/2010
03/01/2011
How do I convert it to sas date? I used following, but it doesn't work
cpn_dt = input(trim(cpn_dt),MMDDYY10.);
How can I fix this?
I really wonder why sas read this as char type with length of 80, because I got this variable via proc sql through odbc to oracle database.

why does SAS not recognize this as a mmddyy10. value?

Well, it seems working for me, please see:
data have;
infile cards;
informat date $80.;
input date ;
cards;
05/21/2010
07/01/2010
03/01/2011
;
data want;
set have;
format _date mmddyy10.;
_date=input(trim(date),MMDDYY10.);
run;
proc sql;
  create table want1 as selectinput(substr(strip(cpn_dt),1,10),MMDDYY10.)
     as cpn_dt format mmddyy10.
        from have;
quit;
proc contents data=want1;run;

No comments:

Post a Comment