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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.