Hello,
i want to insert SYSDATE into an oracle table.
This works:
proc sql noprint threads;
connect to ORACLE as oracle ( user=XX password=XX path=XX );
INSERT INTO oraCon.TABLENAME
(
LAST_UPDATE
)
VALUES
(
'01JAN2016:00:00:00'DT
);
disconnect from oracle;
quit;
But how can i insert sysdate/datetime (the actual date and time) instead of the constant "'01JAN2016:00:00:00'DT"?
Thank you very much.
Best regards
George
Maybe (can't check it):
VALUES ( "%sysfunc(date(),date9.):%sysfunc(time(),tod8.)"dt );
Use the DATETIME() function.
*Create a macro variable;
%let myDate = %sysfunc(datetime(), datetime21.);
*Display macro variable for testing;
%put &myDate;
Maybe (can't check it):
VALUES ( "%sysfunc(date(),date9.):%sysfunc(time(),tod8.)"dt );
Thanks you very much
Best regards
George
The automatic macro variables SYSDATE9 and SYSTIME are set to the date and time when your SAS session started. If you want to use those then change use something like:
proc sql noprint threads;
connect to ORACLE as oracle ( user=XX password=XX path=XX );
INSERT INTO oraCon.TABLENAME (LAST_UPDATE)
VALUES ("&sysdate9:&systime"dt)
;
disconnect from oracle;
quit;
If instead you want to use the current date and time then you can call the DATETIME() function instead. The VALUES statement does not take functions so wrap the function call in the %SYSFUNC() macro function.
VALUES (%sysfunc(datetime()))
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.