BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sorosch
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Maybe (can't check it):

		VALUES
		(
			"%sysfunc(date(),date9.):%sysfunc(time(),tod8.)"dt
		);

View solution in original post

5 REPLIES 5
Reeza
Super User

Use the DATETIME() function. 

 

*Create a macro variable;
%let myDate = %sysfunc(datetime(), datetime21.);

*Display macro variable for testing;
%put &myDate;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Maybe (can't check it):

		VALUES
		(
			"%sysfunc(date(),date9.):%sysfunc(time(),tod8.)"dt
		);
sorosch
Fluorite | Level 6

Thanks you very much

 

Best regards

George

Tom
Super User Tom
Super User

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()))

 

sorosch
Fluorite | Level 6
Thank you very much - works also correct:)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3202 views
  • 4 likes
  • 4 in conversation