Reinhard,
I like to have control over my conversions, so I test the values:
data dt ; length dtc $ 30 dtf $ 3 ; input dtc ;
if prxmatch( "/^\d{4,4}-\d{2,2}-\d{2,2}$/" , strip( dtc )) then do ; dt = input( cats( dtc , "T00:00:00" ) , e8601dt. ) ; dtf = "HMS" ; end ; else if prxmatch( "/^\d{4,4}-\d{2,2}-\d{2,2}T\d{2,2}:\d{2,2}$/" , strip( dtc )) then do ; dt = input( cats( dtc , ":00" ) , e8601dt. ) ; dtf = "S" ; end ;
datalines ; 2012-07-26 2012-07-26T15:41 2012-07-26T15:55 2012-08-08 run ;
proc print data = dt ; format dt datetime16. ; run ;
A few points: it is worth emphasizing that SAS datetimes variables are just a number. How you present that number is controlled by the format. The datetime is at least as refined as seconds, so all of these values are truncated. I include a flag to indicate the level of imputation (I choose "00", but you could also use any value to "59", but SAS will round for the DATETIME16. format). Some standards might represent "HMS" as "H", because if you imputated hours, then minutes and seconds were missing, too (presumably). Lastly, the regular expressions are too broad, but serve for some data.
HTH,
Kevin
... View more