Date Evaluation Inconsistency...

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Date Evaluation Inconsistency...

Hal 9000
List,
This is driving me CRAZYY.

* Prelude:
 **********************************
 **********************************.

* sample data .
new file.
data list free /date(adate).
begin data
'01/01/2007'
end data.

*   This works: .

if (date > 01/01/2006) v1 = 1.

*   This does NOT work: .

if (date < 01/01/2008) v2 = 1.

*************************************
 ************************************.

-Why????

Gratitude,
Gary
Reply | Threaded
Open this post in threaded view
|

Re: Date Evaluation Inconsistency...

Hal 9000
Yes, but as seperate evaluations, one works and one does not.
The idea is that I'd like be be able to do something like:

if (01/01/2006 <= date < 01/01/2008) compute v1 = 1.

I see from a recent post that perhaps using  date.dmy() might solve it, but
it doesn't answer why one would work and not the other.

-Gary


On 12/18/06, Judith Saebel <[hidden email]> wrote:

>
> Doesn't date < 01/01/2008 also include ALL > 01/01/2006?
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Hal 9000
> Sent: Tuesday, 19 December 2006 14:50
> To: [hidden email]
> Subject: Date Evaluation Inconsistency...
>
> List,
> This is driving me CRAZYY.
>
> * Prelude:
> **********************************
> **********************************.
>
> * sample data .
> new file.
> data list free /date(adate).
> begin data
> '01/01/2007'
> end data.
>
> *   This works: .
>
> if (date > 01/01/2006) v1 = 1.
>
> *   This does NOT work: .
>
> if (date < 01/01/2008) v2 = 1.
>
> *************************************
> ************************************.
>
> -Why????
>
> Gratitude,
> Gary
>
Reply | Threaded
Open this post in threaded view
|

Re: Date Evaluation Inconsistency...

Richard Ristow
In reply to this post by Hal 9000
At 11:20 PM 12/18/2006, Hal 9000 wrote:

>This is driving me CRAZYY.
>
>* sample data .
>new file.
>data list free /date(adate).
>begin data
>'01/01/2007'
>end data.
>
>*   This works: .
>if (date > 01/01/2006) v1 = 1.
>
>*   This does NOT work: .
>if (date < 01/01/2008) v2 = 1.

Neither 'works'; the first gave the result you expected, only by
accident. Your expressions "01/01/2006" and "01/01/2008" are not dates;
they are arithmetic expressions that evaluate, respectively, to 1/2006
and 1/2008.

A date in the current century is a very large integer in SPSS. ("A date
is a floating-point number representing the number of seconds from
midnight, October 14, 1582. Dates, which represent a particular point
in time, are stored as the number of seconds to that date. For example,
November 8, 1957, is stored as 1.2E+10."-SPSS 14 Command Syntax
Reference, p.72)

The numeric values of your value 'date' and the two quantities you're
comparing it to, are listed below (SPSS draft output). So that's why it
doesn't work. (Alas, SPSS, unlike SAS, does not have any way to write a
date as a constant.)

Assuming that your dates are mm/dd/yyyy, then either of the following
should be what you want, but I'm not testing - there could be typos.

if (date > 01/01/2006) v1 = 1.
if (date < 01/01/2008) v2 = 1.


if (date > DATE.MDY(01,01,2006)) v1 = 1.
if (date < DATE.MDY(01,01,2008)) v2 = 1.

if (date > NUMBER('01/01/2006',ADATE12) v1 = 1.
if (date < NUMBER('01/01/2008',ADATE12) v2 = 1.




  As an off-list responder has said, you can use


new file.
data list free /date(adate).
begin data
'01/01/2007'
end data.

NUMERIC DateNum(COMMA25).
COMPUTE DateNum = Date.

*   This works: .
if (date > 01/01/2006) v1 = 1.

*   This does NOT work: .
if (date < 01/01/2008) v2 = 1.

COMPUTE    Compare1 = 01/01/2006.
COMPUTE    Compare2 = 01/01/2008.
FORMATS    Compare1 Compare2 (E13.6).

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |19-DEC-2006 00:02:05       |
|-----------------------------|---------------------------|

The variables are listed in the following order:

LINE   1: date DateNum v1 v2
LINE   2: Compare1 Compare2


         date: 01/01/2007            13,386,988,800     1.00      .
     Compare1: 4.985045E-004 4.980080E-004

Number of cases read:  1    Number of cases listed:  1