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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

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;

sassharp
Calcite | Level 5

my dates are in oracle form because I am running against oracl db

art297
Opal | Level 21

But they might still import in SAS form.  I would try running the suggested code and check what you get.

sassharp
Calcite | Level 5

Thank you art297 for your reply.

Is there any function like "nvl" in oracle pass through which works in proc sql?

Reeza
Super User

coalesce

Reeza
Super User

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;

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!

What is Bayesian Analysis?

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.

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
  • 6 replies
  • 52346 views
  • 3 likes
  • 3 in conversation