Missing in COMPUTE statements

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

Missing in COMPUTE statements

Robert L
I just got this question where a user got unexpected results when combining variables. I tried to recreate the problem. The following syntax is run:

DATA LIST FIXED/v1 1 v2 2.
BEGIN DATA
1
 1
11
 2
13
END DATA.
DATASET NAME test WINDOW=FRONT.

IF (v1=1) AND (v2>=2) k1=1.
COMPUTE k2=(v1=1) AND (v2 >= 2).

EXECUTE.

FORMATS k1 k2 (F1).

The k1 variable runs as expected, it is only when both conditions are satisfied that the result is a 1, otherwise it is empty. But the k2 variable, why does it end with a 1 when v1 is empty and v2=1 (the second row)? It seems OK for the line before where v1=1 and v2 is empty.

I must be missing something here?

Robert

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Robert Lundqvist
Reply | Threaded
Open this post in threaded view
|

Re: Missing in COMPUTE statements

Kirill Orlov
The result is

v1 v2 k1 k2

  1  .  .  .
  .  1  .  0
  1  1  .  0
  .  2  .  .
  1  3  1  1

which is normal.

The IF can assign only 1. Or leave sysmis.
The COMPUTE assignes either 1 or 0, or leaves sysmis. In case 5 it
returns 1 because both logical conditions (conjuncted by AND) are true.
In case 3 it returns 0 because one of the conditions is true and the
other is false.
In case 2 it returnes 0 because one of the conditions cannot be
evaluated yet the other is false, which is sufficient to declare the
complete statement false.


01.11.2019 14:28, Robert Lundqvist пишет:

> I just got this question where a user got unexpected results when combining variables. I tried to recreate the problem. The following syntax is run:
>
> DATA LIST FIXED/v1 1 v2 2.
> BEGIN DATA
> 1
>   1
> 11
>   2
> 13
> END DATA.
> DATASET NAME test WINDOW=FRONT.
>
> IF (v1=1) AND (v2>=2) k1=1.
> COMPUTE k2=(v1=1) AND (v2 >= 2).
>
> EXECUTE.
>
> FORMATS k1 k2 (F1).
>
> The k1 variable runs as expected, it is only when both conditions are satisfied that the result is a 1, otherwise it is empty. But the k2 variable, why does it end with a 1 when v1 is empty and v2=1 (the second row)? It seems OK for the line before where v1=1 and v2 is empty.
>
> I must be missing something here?
>
> Robert
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Missing in COMPUTE statements

Robert L
In reply to this post by Robert L
Thanks for the response. I was not aware that as you say "The IF can assign only 1. Or leave sysmis." But that still does not seem to explain why case 1 does not return a 0 as case 2 for the k2 variable?

With k2=(v1=1) AND (v2 >= 2), the first part is true and the other cannot be evaluated. If case 2 ends in false, shouldn't case 1 do the same?

Robert

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Kirill Orlov
Skickat: den 1 november 2019 12:47
Till: [hidden email]
Ämne: Re: Missing in COMPUTE statements

The result is

v1 v2 k1 k2

  1  .  .  .
  .  1  .  0
  1  1  .  0
  .  2  .  .
  1  3  1  1

which is normal.

The IF can assign only 1. Or leave sysmis.
The COMPUTE assignes either 1 or 0, or leaves sysmis. In case 5 it returns 1 because both logical conditions (conjuncted by AND) are true.
In case 3 it returns 0 because one of the conditions is true and the other is false.
In case 2 it returnes 0 because one of the conditions cannot be evaluated yet the other is false, which is sufficient to declare the complete statement false.


01.11.2019 14:28, Robert Lundqvist пишет:

> I just got this question where a user got unexpected results when combining variables. I tried to recreate the problem. The following syntax is run:
>
> DATA LIST FIXED/v1 1 v2 2.
> BEGIN DATA
> 1
>   1
> 11
>   2
> 13
> END DATA.
> DATASET NAME test WINDOW=FRONT.
>
> IF (v1=1) AND (v2>=2) k1=1.
> COMPUTE k2=(v1=1) AND (v2 >= 2).
>
> EXECUTE.
>
> FORMATS k1 k2 (F1).
>
> The k1 variable runs as expected, it is only when both conditions are satisfied that the result is a 1, otherwise it is empty. But the k2 variable, why does it end with a 1 when v1 is empty and v2=1 (the second row)? It seems OK for the line before where v1=1 and v2 is empty.
>
> I must be missing something here?
>
> Robert
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except
> the command. To leave the list, send the command SIGNOFF SPSSX-L For a
> list of commands to manage subscriptions, send the command INFO
> REFCARD
>
>

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Robert Lundqvist
Reply | Threaded
Open this post in threaded view
|

Re: Missing in COMPUTE statements

Kirill Orlov
But your

IF (v1=1) AND (v2>=2) k1=1.

command does not request to assign value 0 at all, ever. On the other
hand, your COMPUTE command requests to assign either 1 (true) OR 0 (false).


04.11.2019 18:33, Robert Lundqvist пишет:

> Thanks for the response. I was not aware that as you say "The IF can assign only 1. Or leave sysmis." But that still does not seem to explain why case 1 does not return a 0 as case 2 for the k2 variable?
>
> With k2=(v1=1) AND (v2 >= 2), the first part is true and the other cannot be evaluated. If case 2 ends in false, shouldn't case 1 do the same?
>
> Robert
>
> -----Ursprungligt meddelande-----
> Från: SPSSX(r) Discussion [mailto:[hidden email]] För Kirill Orlov
> Skickat: den 1 november 2019 12:47
> Till: [hidden email]
> Ämne: Re: Missing in COMPUTE statements
>
> The result is
>
> v1 v2 k1 k2
>
>    1  .  .  .
>    .  1  .  0
>    1  1  .  0
>    .  2  .  .
>    1  3  1  1
>
> which is normal.
>
> The IF can assign only 1. Or leave sysmis.
> The COMPUTE assignes either 1 or 0, or leaves sysmis. In case 5 it returns 1 because both logical conditions (conjuncted by AND) are true.
> In case 3 it returns 0 because one of the conditions is true and the other is false.
> In case 2 it returnes 0 because one of the conditions cannot be evaluated yet the other is false, which is sufficient to declare the complete statement false.
>
>
> 01.11.2019 14:28, Robert Lundqvist пишет:
>> I just got this question where a user got unexpected results when combining variables. I tried to recreate the problem. The following syntax is run:
>>
>> DATA LIST FIXED/v1 1 v2 2.
>> BEGIN DATA
>> 1
>>    1
>> 11
>>    2
>> 13
>> END DATA.
>> DATASET NAME test WINDOW=FRONT.
>>
>> IF (v1=1) AND (v2>=2) k1=1.
>> COMPUTE k2=(v1=1) AND (v2 >= 2).
>>
>> EXECUTE.
>>
>> FORMATS k1 k2 (F1).
>>
>> The k1 variable runs as expected, it is only when both conditions are satisfied that the result is a 1, otherwise it is empty. But the k2 variable, why does it end with a 1 when v1 is empty and v2=1 (the second row)? It seems OK for the line before where v1=1 and v2 is empty.
>>
>> I must be missing something here?
>>
>> Robert
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>> [hidden email] (not to SPSSX-L), with no body text except
>> the command. To leave the list, send the command SIGNOFF SPSSX-L For a
>> list of commands to manage subscriptions, send the command INFO
>> REFCARD
>>
>>
> =====================
> To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD