Convert character dates into numeric

is there a way to convert a character date for example: 11-1900 that is November 1900 into a numeric date? Thank you in advance. I’m familiar with dates made by ddmmyy but not with only mmyy.


>Solution :

You could use the ANYDTDTE. informat. But note that is a GUESSING procedure that tries to figure out if the string matches any of a number of different styles of representing dates. Might be better to just add your own day of the month prefix and use the DDMMYY informat instead. Then strange values will not accidentally result in valid but strange date values.

data have;
  input string $ ;

data want;
  set have;
  date1= input(string,anydtdte.);
  date2= input('01-'||string,ddmmyy10.);
  format date1 date2 date9.;

Leave a Reply