I do need to fix sas date formats here.
proc sql;
create table DATE as
select
case when i.dateofdeath =. then "31dec9999:00:00:0"dt
else i.dateofdeath end as ddate
from lib.ind as i
where region='x';
quit;
when I ran this query from SAS (lib is referenced for libname) I am getting ddate as 253717660800 for 31dec9999:00:00:0 and 1643587200 for 1/31/2012(in oracle dateofdeath column).
Q. I do need output ddate as in this format 01JAN2011:00:00:00?
Not sure if your dates are in SAS or oracle form, but you could try just adding a format statement. e.g.:
proc sql;
create table DATE as
select
case when i.dateofdeath =. then "31dec9999:00:00:0"dt
else i.dateofdeath end as ddate
format=datetime21.
from lib.ind as i
where region='x';
quit;
Not sure if your dates are in SAS or oracle form, but you could try just adding a format statement. e.g.:
proc sql;
create table DATE as
select
case when i.dateofdeath =. then "31dec9999:00:00:0"dt
else i.dateofdeath end as ddate
format=datetime21.
from lib.ind as i
where region='x';
quit;
my dates are in oracle form because I am running against oracl db
But they might still import in SAS form. I would try running the suggested code and check what you get.
Thank you art297 for your reply.
Is there any function like "nvl" in oracle pass through which works in proc sql?
coalesce
You can also consider using the datepart function if you're not interested in the time format (I rarely am, except when looking at ER info).
This might affect your running time, so keep that in mind.
proc sql;
create table DATE as
select
case when i.dateofdeath =. then "31dec9999"dt
else datepart(i.dateofdeath) end as ddate format date9.
from lib.ind as i
where region='x';
quit;
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.