title: Inserting date/time in a SQL table in SAS
body: <p>I am having a little issue inserting the date time into a database table name (TestTable) in SAS EG. The date fields in the TestTable are defined as </p>
  
  <pre><code>Name = EnteredDate  
  Type = Date
  Length = 8
  Format = DATETIME22.3
  Informat = DATETIME22.3
  
  Name = LastUpdateDate  
  Type = Date
  Length = 8
  Format = DATETIME22.3
  Informat = DATETIME22.3
  </code></pre>
  
  <p>My existing code is as follows, where i use a select statement to insert as opposed to a values statement. Here is call a PrepTable which I dont use at all, but the select statement allows me to use the datetime() function which works perfectly in inserting the date time without any issues. See below:</p>
  
  <pre><code>INSERT INTO LIBNAME.TestTable (Statuscode, EnteredDate, LastUpdateDate)
  Select '2', datetime(), datetime()
  From work.PrepTable
  </code></pre>
  
  <p>I want to do the following:</p>
  
  <pre><code>INSERT INTO LIBNAME.TestTable (Statuscode, EnteredDate, LastUpdateDate)
  VALUES ('2', datetime(), date time()) 
  </code></pre>
  
  <p>This is far more efficient I think since I dont have to query the work.PrepTable. But datetime() will not work in a values statement. I tried the following variations</p>
  
  <pre><code>INSERT INTO LIBNAME.TestTable (Statuscode, EnteredDate, LastUpdateDate)
  VALUES ('2', "&amp;sysdate9:00:00:00"dt,"&amp;sysdate9:00:00:00"dt)
  </code></pre>
  
  <p>This method does not enter the time only the date and the date entered is wrong as well. Another variation I tried is the following after looking around on this site</p>
  
  <pre><code>INSERT INTO LIBNAME.TestTable (Statuscode, EnteredDate, LastUpdateDate)
  VALUES ('2', &amp;today_dttm,&amp;today_dttm)
  </code></pre>
  
  <p>where &amp;today_dttm is sourced from:</p>
  
  <pre><code>%let today_dttm=%sysfunc(dhms(%sysfunc(today()), 0, 0, 0));
  </code></pre>
  
  <p>This hasn't worked to well either as i keep getting only just the date inserted and not the time. Is there a proper way to enter the current day and time when the insert statement is called without having to use the Select statement and datetime() combo.</p>
  
  <p>I am a newbie to sas and any input would be greatly appreciated.
  Thanks</p>