BookmarkSubscribeRSS Feed
alepage
Barite | Level 11

Hello,

 

In my SAS dataset, the content of the variable HRDEBTRA look like : 14:50:05

Then if the Oracle table does not exist, I am using a proc append

 

proc append base=&libref..&table_name data=&table_name;
run;

where &libref is the name of the oracle schema, and table_name is the table name (target table)

work.&table_name (source table)

if the Oracle table exist the we update the table using the script below:

 

options sastrace=',,;d' sastraceloc=saslog nostsuffix; 
proc sql;
connect to oracle (AUTHDOMAIN=ORACLE_&OWNER._&Database. PATH=&Database. readbuff=1000);
execute(
MERGE INTO &schema..&TblName1. pt 
USING &SCHEMA..&TblName2. ps 
ON    (pt.recordId = ps.recordId) 
WHEN NOT MATCHED THEN INSERT VALUES
(&varlist1.)
WHEN MATCHED THEN UPDATE 
  SET 
  &varlist2.
) BY ORACLE;
DISCONNECT FROM ORACLE;
quit;

However, the variable HRDEBTRA in the Oracle table is like a date.

What's the best way to convert that funzy date to HH24:mm:ss ex: 14:50:05

 

 

2/1/2024 2:50:05 PM

4 REPLIES 4
Patrick
Opal | Level 21

"In my SAS dataset, the content of the variable HRDEBTRA look like : 14:50:05"

 

SAS stores time and datetime values in a numerical variable as count of seconds. It's then the format attached to the variable that determines how this count of second gets displayed.

 

It looks like your variable only stores a time value - which is just a count of seconds. 

 

In Oracle you normally store such data as a datetime value for which there are two data types: datetime and timestamp. 

 

The easiest way to prepare your SAS data for loading into Oracle would be to convert your SAS Time value to a SAS DateTime value. That's not hard to do IF you know the calendar date that would match the time portion you've already got. 

 

On the SAS side: Could you convert 14:50:05 to something like 02Jan2024:14:50:05 ? Do you have this date information somewhere in your data?

alepage
Barite | Level 11

No, 2/1/2024 , I dont' know where does come from this date ?

Sajid01
Meteorite | Level 14

Hello @alepage 
Oracle date is actually datetime value.  There is no specific time variable AFAIK in Oracle.
If it is required to store only time values OR if the variable holds only time, then the appropriate approach would be to either  convert the time to a number (for example number of seconds since midnight- the default SAS storage for time) OR to save time as a character string (thus 14:50:05 would be '14:50:05') and pass the string to ORACLE.

 

SASKiwi
PROC Star

@alepage  - If you are required to update an Oracle datatime column, then you have no choice but to add a date to your time value. If you don't know what date needs to be supplied then ask your Oracle administrator or someone knowledgeable about the table contents for advice.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 432 views
  • 1 like
  • 4 in conversation