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 |
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.
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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.