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
Name = EnteredDate
Type = Date
Length = 8
Format = DATETIME22.3
Informat = DATETIME22.3
Name = LastUpdateDate
Type = Date
Length = 8
Format = DATETIME22.3
Informat = DATETIME22.3
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:
INSERT INTO LIBNAME.TestTable (Statuscode, EnteredDate, LastUpdateDate)
Select '2', datetime(), datetime()
From work.PrepTable
I want to do the following:
INSERT INTO LIBNAME.TestTable (Statuscode, EnteredDate, LastUpdateDate)
VALUES ('2', datetime(), date time())
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
INSERT INTO LIBNAME.TestTable (Statuscode, EnteredDate, LastUpdateDate)
VALUES ('2', "&sysdate9:00:00:00"dt,"&sysdate9:00:00:00"dt)
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
INSERT INTO LIBNAME.TestTable (Statuscode, EnteredDate, LastUpdateDate)
VALUES ('2', &today_dttm,&today_dttm)
where &today_dttm is sourced from:
%let today_dttm=%sysfunc(dhms(%sysfunc(today()), 0, 0, 0));
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.
I am a newbie to sas and any input would be greatly appreciated. Thanks