title: SAS Date Informat with Milliseconds
body: <p>I am trying to create a SAS informat for the following date format:</p>
  
  <p>"yyyy-mm-dd hh:ii:ss.SSS UTC", example: "2016-01-14 10:31:01.456 UTC"</p>
  
  <p>I've gotten close using the following format code:</p>
  
  <pre><code>PROC FORMAT;
      PICTURE MyDate other='%0Y-%0m-%0d %0H:%0M:%0s UTC' (datatype=datetime);
  RUN;
  </code></pre>
  
  <p>Unfortunately when I try and use this as an INFORMAT I get an error "can't find format MyDate", as it hasn't been defined as an informat, just an output format. </p>
  
  <p>I can try and create an informat from a dataset created from this format, but due to the milliseconds constraint it will only create values that map to times with .000 in the milliseconds section.  For example:</p>
  
  <pre><code>DATA MyInDate ;
      RETAIN FMTNAME "MyInputDate" type "I" ;
      do label = "1jan2016:00:00:00"dt to
                 "2feb2016:00:00:00"dt by 1;
          start = trim(left(put(label,MyDate.)));
          output ;
      end ;
  RUN;
  PROC FORMAT CNTLIN=MyInDate;
  RUN;
  </code></pre>
  
  <p>Even if I were able to enumerate a dataset with milliseconds it would be prohibitively large.  Since my dates can span years.</p>
  
  <p>Is it possible to truncate my input data BEFORE passing it to the informat?  I don't care about the milliseconds or the UTC qualifier.  I can't change the input data.</p>
  
  <p>EDIT: Using <code>anydtdtm.</code> as an informat results in empty values without error messages. Here is the data step making use of this informat:</p>
  
  <pre><code>DATA WORK.ImportDatTest;
  LENGTH
      'Event Time'n    8
  ;
  FORMAT
      'Event Time'n    DATETIME25.
  ;
  INFORMAT
      'Event Time'n       anydtdtm.
  ;
  INFILE DATALINES DLM=','
      ;
  INPUT
      'Event Time'n    : ANYDTDTM.
  ;
  DATALINES;
  2016-01-11 17:23:34.834 UTC
  2016-01-11 17:23:34.834 UTC
  2016-01-11 17:23:34.834 UTC
  ;
  
  RUN;
  </code></pre>