Help using Base SAS procedures

date formats in proc sql

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 110
Accepted Solution

date formats in proc sql

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?


Accepted Solutions
Solution
‎02-20-2012 03:50 PM
PROC Star
Posts: 7,364

date formats in proc sql

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


All Replies
Solution
‎02-20-2012 03:50 PM
PROC Star
Posts: 7,364

date formats in proc sql

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;

Frequent Contributor
Posts: 110

date formats in proc sql

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

PROC Star
Posts: 7,364

date formats in proc sql

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

Frequent Contributor
Posts: 110

date formats in proc sql

Thank you art297 for your reply.

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

Super User
Posts: 17,912

date formats in proc sql

coalesce

Super User
Posts: 17,912

date formats in proc sql

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 42745 views
  • 3 likes
  • 3 in conversation