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

Hello !!

I want to retrieve null date from a table but getting below error.

Date retrieval will be null or in '00-___-0000' format (dd-mon-yyyy)

proc sql;

select date from tablex

where (date is null or date like '00-___-0000') ;

quit;

Error in log---Invalid date/time/datetime constant '00-___-0000'd.

Can anyone help me.

Advance thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Are you referencing the Oracle table from SAS using implicit pass through?  For example by using a libname with the ORACLE engine.

If so then SAS will have already converted the invalid dates that you have in your date variable in Oracle into missing values.  You will not be able to tell the difference between a value that Oracle considers null and one in that strange date format with zeros both will stored as SAS missing values.

libname mylib oracle .... ;

proc sql ;

  create table nodates as

    select * from mylib.tablex

    where date is missing

  ;

quit;

View solution in original post

7 REPLIES 7
Linlin
Lapis Lazuli | Level 10

try:

proc sql;

select date from tablex

where date =. ;/*  or date=' ' if date is character variable*/

quit;

dash
Obsidian | Level 7

Thanks Linin.

In the Oracle, when retrieving date with dd-mon-yyyy format (00-000-0000), we are writing using like operator --> date like '00-___-0000'.

Can we use like operator in SAS ?

Linlin
Lapis Lazuli | Level 10

Yes. An example:

proc sql;

select name from sashelp.class

where upcase(name) like "A%";

quit;

                                              Name

                                           

                                             Alfred

                                             Alice

dash
Obsidian | Level 7

Hello Linin,

If the dataset are like below, I want to get pid (012 and 013).

data x;

input  pid  dob : ddmmyy10. ;

cards;

011 23-jan-2012

012 00-000-0000

013 .

014 11-mar-2011

;

proc sql;

create table y as

select * from x

where dob=.;

quit;

Linlin
Lapis Lazuli | Level 10

Hi,

try the code below:

data x;
input  pid $3.  dob $12. ;
cards;
011 23-jan-2012
012 00-000-0000
013 .
014 11-mar-2011
;
data temp;
  set x;
  newdob=input(dob,??date11.);
  format newdob date9.;

proc sql;
create table y as
select * from temp
where newdob is missing;
quit;
proc print data=y;run;

dash
Obsidian | Level 7

Thanks linin for your nice explanation

Tom
Super User Tom
Super User

Are you referencing the Oracle table from SAS using implicit pass through?  For example by using a libname with the ORACLE engine.

If so then SAS will have already converted the invalid dates that you have in your date variable in Oracle into missing values.  You will not be able to tell the difference between a value that Oracle considers null and one in that strange date format with zeros both will stored as SAS missing values.

libname mylib oracle .... ;

proc sql ;

  create table nodates as

    select * from mylib.tablex

    where date is missing

  ;

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!

How to Concatenate Values

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.

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