0
votes

I imported 5 excel files into SAS and there are some dates formatted as 8/3/1989 originally and formatted into 03Aug1989 (DATE9.) which is what I really want. However, on 1 file the dates failed to converted into DATE9. and it is read as $CHAR10 when I read the log. I tried several ways to reformat it into DATE9 but failed.

  1. I tried to change all informat/format/input into DATE9. instead of $CHAR10 but failed, the results are all empty (.)
  2. I tried DateNew=input (Date,DATE9.); but it didn't work either.

Any comment?

Thanks!

1
Try the suggestions in stackoverflow.com/questions/22924104/… and see if that helps.Joe

1 Answers

0
votes

Joe's suggestion in the comment should be plan A. But occasionally built-in SAS format-specifying options don't work and you still end up with a string. If that's where you're at, here's a good fallback:

data test;
format imported_date $char10.;
imported_date = "8/3/1989";

month = scan(imported_date, 1, "/")*1;
day = scan(imported_date, 2, "/")*1;
year = scan(imported_date, 3, "/")*1;

date_datefmt = mdy(month,day,year);
format date_datefmt date9.;
run;