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
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.
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;
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
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.
Hi Laurie,
You are right. Oracle converted to the format i wanted internally. Thanks for the suggestion.
Thanks,
Ana
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.