BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Toni2
Lapis Lazuli | Level 10

I have spent hours on this and i am still struggling to figure out the issue 

 

For some reason SAS doesn't recognise the comparison "if date>=31/01/98" even though i have already formatted date variable. The outcome for variable test is always 1  even for dates prior to 31/01/98

 

Any help would be appreciated ?  

 

 

data b;
informat date anydtdte12.;
set a;
format date ddmmyy8.;
run;

 

data c;
set b;
if date>=31/01/98 then test = 1;else test=0;
run;

 

Obs date test
1 31/01/1997 1
2 28/02/1997 1
3 31/03/1997 1
4 30/04/1997 1
5 31/05/1997 1
6 30/06/1997 1
7 31/07/1997 1
8 31/08/1997 1
9 30/09/1997 1
10 31/10/1997 1
11 30/11/1997 1
12 31/12/1997 1
13 31/01/1998 1
14 28/02/1998 1
15 31/03/1998 1
16 30/04/1998 1
17 31/05/1998 1
18 30/06/1998 1
19 31/07/1998 1
20 31/08/1998 1
21 30/09/1998 1
22 31/10/1998 1
23 30/11/1998 1
24 31/12/1998 1
25 31/01/1999 1
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

31/01/98 is not a date, even if it looks like one to you. It is 31 divided by 01 divided by 98.

 

What you really want is

 

if date>='31JAN1998'd then test = 1;else test=0;

Also, this is not a FORMAT issue, it doesn't matter what format is assigned to variable DATE.

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

31/01/98 is not a date, even if it looks like one to you. It is 31 divided by 01 divided by 98.

 

What you really want is

 

if date>='31JAN1998'd then test = 1;else test=0;

Also, this is not a FORMAT issue, it doesn't matter what format is assigned to variable DATE.

 

--
Paige Miller
Toni2
Lapis Lazuli | Level 10
thank you!
Kurt_Bremser
Super User

And if you do not like the DATE9 format used in SAS date literals, use the INPUT function:

if date >= input("31/01/1998",ddmmyy10.)
then test = 1;
else test = 0;

And do not use 2-digit years, unless you like to be bitten in the behind by your own code sooner or later.

Toni2
Lapis Lazuli | Level 10
thank you quite useful! 🙂

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1008 views
  • 0 likes
  • 3 in conversation