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

Hi SAS users,

 

Need help with generating charcter date like below to DATE format to insert into ORacle Database.

 

I tried the below way in  EG & got it to the default date of SAS than the original date. where i am doing wrong?

 

data test;
date1 = '10/15/2017';

run;

 

 

proc sql;
create table test2 as
select
input(date1, MMDDYY10.) AS date2 format = DATETIME20.
from test
;
QUIT;

 

Thanks,

Ana

1 ACCEPTED SOLUTION

Accepted Solutions
LaurieF
Barite | Level 11

Oh, OK. What happens when you pass it to Oracle once you've done that? As long as the variable's format is set to datetime and the value is in seconds, the Oracle engine should do anything it needs to do for you.

View solution in original post

4 REPLIES 4
LaurieF
Barite | Level 11

You're almost there. You have to convert it from date (days since 1Jan1960) to datetime (seconds from…). The dhms function does this:

data test;
date1 = '10/15/2017';
run;
 
 
proc sql;
create table test2 as
select
dhms(input(date1, MMDDYY10.), 0, 0, 0) AS date2 format = DATETIME20.
from test
;
QUIT;
SASAna
Quartz | Level 8

Thank you. I tried below ways too.

 

proc sql;
create table test2 as
select
input(date1, MMDDYY10.) * 86400 AS date2 format = DATETIME20. ,
input(date1,anydtdtm20.) AS date3 format = DATETIME. ,
dhms(input(date1, MMDDYY10.), 0, 0, 0) AS date4 format = DATETIME20.
from test
;
QUIT;

 

All date2, date3, date4 were giving me results like -  

15OCT2017:00:00:00          15OCT17:00:00:00          15OCT2017:00:00:00

 

I am looking for "9/20/2015 12:00:00 AM" format .

 

Thanks,

Ana

LaurieF
Barite | Level 11

Oh, OK. What happens when you pass it to Oracle once you've done that? As long as the variable's format is set to datetime and the value is in seconds, the Oracle engine should do anything it needs to do for you.

SASAna
Quartz | Level 8

Hi Laurie,

 

You are right. Oracle converted to the format i wanted internally. Thanks for the suggestion.

 

Thanks,

Ana

sas-innovate-2024.png

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.

 

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