DO IF + COMPUTE Command not computing all statements SPSS v.23

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

DO IF + COMPUTE Command not computing all statements SPSS v.23

Maria Suchard
Good Morning Listers,

I am working on SPSS version 23 and I am running a DO IF + Compute command- the command it is not taking into account all of the variables and I am getting false negatives.  In the command, I want to create a new variable based off four other variables. Syntax is listed below. What i want the syntax to do is create the NORMSTAT=1 if there is a value for SEX (1,2), ENRLSTAT=3, ENTER1st=1 OR ENTERCUR=1. Where I am finding the issue is that if there is a value for SEX (1,2), ENRLSTAT (3), but ENTER1ST=0 AND ENTERCUR=1, the result for NORMSTAT=2 not NORMSTAT=1. I have looked at the other discussions in the listserv .  Is there a better, more efficient way to write this code so it performs that I want?

With appreciation,
Maria

RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
MISSING VALUES ENTER1ST ENTERCUR (0).
COMPUTE NORMSTAT=2.

DO IF ANY (SEX,1,2) AND ENRLSTAT=3
AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)).
COMPUTE NORMSTAT=1.
END IF.
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

Rich Ulrich
Your description says ENTERCUR=1 rather than what you have
coded, which is (ENTER1st= 0 AND ENTERCUR=1).

You can simplify and also match your description by using ANY( ) in its
other form,  ANY(value, var, var).  That is:

DO IF   ANY(SEX,1,2) AND ENRLSTAT=3  AND ANY(1, ENTER1ST, ENTERCUR).

--
Rich Ulrich


> Date: Tue, 23 Aug 2016 08:50:59 -0700

> From: [hidden email]
> Subject: DO IF + COMPUTE Command not computing all statements SPSS v.23
> To: [hidden email]
>
> Good Morning Listers,
>
> I am working on SPSS version 23 and I am running a DO IF + Compute command-
> the command it is not taking into account all of the variables and I am
> getting false negatives. In the command, I want to create a new variable
> based off four other variables. Syntax is listed below. What i want the
> syntax to do is create the NORMSTAT=1 if there is a value for SEX (1,2),
> ENRLSTAT=3, ENTER1st=1 OR ENTERCUR=1. Where I am finding the issue is that
> if there is a value for SEX (1,2), ENRLSTAT (3), but ENTER1ST=0 AND
> ENTERCUR=1, the result for NORMSTAT=2 not NORMSTAT=1. I have looked at the
> other discussions in the listserv . Is there a better, more efficient way
> to write this code so it performs that I want?
>
> With appreciation,
> Maria
>
> RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
> MISSING VALUES ENTER1ST ENTERCUR (0).
> COMPUTE NORMSTAT=2.
>
> DO IF ANY (SEX,1,2) AND ENRLSTAT=3
> AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)).
> COMPUTE NORMSTAT=1.
> END IF.
>

===================== 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: DO IF + COMPUTE Command not computing all statements SPSS v.23

David Marso
Administrator
In reply to this post by Maria Suchard

Do some refresher reading on how MISSING VALUES are treated in Logical statements.
Might want to look at the VALUE function as well.

Maria Suchard wrote
Good Morning Listers,

I am working on SPSS version 23 and I am running a DO IF + Compute command- the command it is not taking into account all of the variables and I am getting false negatives.  In the command, I want to create a new variable based off four other variables. Syntax is listed below. What i want the syntax to do is create the NORMSTAT=1 if there is a value for SEX (1,2), ENRLSTAT=3, ENTER1st=1 OR ENTERCUR=1. Where I am finding the issue is that if there is a value for SEX (1,2), ENRLSTAT (3), but ENTER1ST=0 AND ENTERCUR=1, the result for NORMSTAT=2 not NORMSTAT=1. I have looked at the other discussions in the listserv .  Is there a better, more efficient way to write this code so it performs that I want?

With appreciation,
Maria

RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
MISSING VALUES ENTER1ST ENTERCUR (0).
COMPUTE NORMSTAT=2.

DO IF ANY (SEX,1,2) AND ENRLSTAT=3
AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)).
COMPUTE NORMSTAT=1.
END IF.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

David Marso
Administrator
In reply to this post by Maria Suchard
Do some refresher reading on how MISSING VALUES are treated in Logical
statements.
Might want to look at the VALUE function as well.


Maria Suchard wrote

> Good Morning Listers,
>
> I am working on SPSS version 23 and I am running a DO IF + Compute
> command- the command it is not taking into account all of the variables
> and I am getting false negatives.  In the command, I want to create a new
> variable based off four other variables. Syntax is listed below. What i
> want the syntax to do is create the NORMSTAT=1 if there is a value for SEX
> (1,2), ENRLSTAT=3, ENTER1st=1 OR ENTERCUR=1. Where I am finding the issue
> is that if there is a value for SEX (1,2), ENRLSTAT (3), but ENTER1ST=0
> AND ENTERCUR=1, the result for NORMSTAT=2 not NORMSTAT=1. I have looked at
> the other discussions in the listserv .  Is there a better, more efficient
> way to write this code so it performs that I want?
>
> With appreciation,
> Maria
>
> RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
*
> MISSING VALUES ENTER1ST ENTERCUR (0).
*
> COMPUTE NORMSTAT=2.
>
> DO IF ANY (SEX,1,2) AND ENRLSTAT=3
> AND (
*
> ENTER1ST=1
*
>  OR (
*
> ENTER1ST=0
*
>  AND ENTERCUR=1)).
> COMPUTE NORMSTAT=1.
> END IF.





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/DO-IF-COMPUTE-Command-not-computing-all-statements-SPSS-v-23-tp5732961p5732963.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

Maria Suchard
In reply to this post by David Marso
Thank you, David. I am reviewing that now.
Reply | Threaded
Open this post in threaded view
|

Fwd: RE: DO IF + COMPUTE Command not computing all statements SPSS v.23

Rick Oliver
In reply to this post by David Marso

Sorry. I accidentally sent this response to David.

---------- Forwarded message ----------
From: "Rick Oliver" <[hidden email]>
Date: Aug 23, 2016 1:50 PM
Subject: RE: DO IF + COMPUTE Command not computing all statements SPSS v.23
To: "David Marso" <[hidden email]>
Cc:

Yes, the condition ENTER1ST=0 will never be met because 0 has been defined as missing for that variable. If you really want to check for this condition and really want 0 to missing, use the VALUE function, as in:

 

data list free /x.

begin data

1 2 3 4 

end data.

missing values x (4).

*this condition will never be met.

do if x=4.

compute y=1.

end if.

*this one works.

do if value(x)=4.

compute z=1.

end if.

list.

 

Sent from Mail for Windows 10

 

From: [hidden email]
Sent: Tuesday, August 23, 2016 12:53 PM
To: [hidden email]
Subject: Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

 

Do some refresher reading on how MISSING VALUES are treated in Logical

statements.

Might want to look at the VALUE function as well.

 

 

Maria Suchard wrote

> Good Morning Listers,

>

> I am working on SPSS version 23 and I am running a DO IF + Compute

> command- the command it is not taking into account all of the variables

> and I am getting false negatives.  In the command, I want to create a new

> variable based off four other variables. Syntax is listed below. What i

> want the syntax to do is create the NORMSTAT=1 if there is a value for SEX

> (1,2), ENRLSTAT=3, ENTER1st=1 OR ENTERCUR=1. Where I am finding the issue

> is that if there is a value for SEX (1,2), ENRLSTAT (3), but ENTER1ST=0

> AND ENTERCUR=1, the result for NORMSTAT=2 not NORMSTAT=1. I have looked at

> the other discussions in the listserv .  Is there a better, more efficient

> way to write this code so it performs that I want?

>

> With appreciation,

> Maria

>

> RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).

*

> MISSING VALUES ENTER1ST ENTERCUR (0).

*

> COMPUTE NORMSTAT=2.

>

> DO IF ANY (SEX,1,2) AND ENRLSTAT=3

> AND (

*

> ENTER1ST=1

*

>  OR (

*

> ENTER1ST=0

*

>  AND ENTERCUR=1)).

> COMPUTE NORMSTAT=1.

> END IF.

 

 

 

 

 

-----

Please reply to the list and not to my personal email.

Those desiring my consulting or training services please feel free to email me.

---

"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."

Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"

--

View this message in context: http://spssx-discussion.1045642.n5.nabble.com/DO-IF-COMPUTE-Command-not-computing-all-statements-SPSS-v-23-tp5732961p5732963.html

Sent from the SPSSX Discussion mailing list archive at Nabble.com.

 

=====================

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: DO IF + COMPUTE Command not computing all statements SPSS v.23

David Marso
Administrator
This post was updated on .
In reply to this post by Maria Suchard
The following should do the same thing (note MISSING VALUES command done after IF).
RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
IF ANY (SEX,1,2)
   AND ENRLSTAT=3
   AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1.
IF MISSING(NORMSTAT) NORMSTAT=2.
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).


Maria Suchard wrote
Good Morning Listers,

I am working on SPSS version 23 and I am running a DO IF + Compute command- the command it is not taking into account all of the variables and I am getting false negatives.  In the command, I want to create a new variable based off four other variables. Syntax is listed below. What i want the syntax to do is create the NORMSTAT=1 if there is a value for SEX (1,2), ENRLSTAT=3, ENTER1st=1 OR ENTERCUR=1. Where I am finding the issue is that if there is a value for SEX (1,2), ENRLSTAT (3), but ENTER1ST=0 AND ENTERCUR=1, the result for NORMSTAT=2 not NORMSTAT=1. I have looked at the other discussions in the listserv .  Is there a better, more efficient way to write this code so it performs that I want?

With appreciation,
Maria

RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
MISSING VALUES ENTER1ST ENTERCUR (0).
COMPUTE NORMSTAT=2.

DO IF ANY (SEX,1,2) AND ENRLSTAT=3
AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)).
COMPUTE NORMSTAT=1.
END IF.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

John F Hall
In reply to this post by Maria Suchard
Another way is:
count x = SEX (1,2), ENRLSTAT(3), ENTER1st(1) ENTERCUR (1).
x will have theoretical range of 0 to 4, but 1 - 4 because of sex.
Values 3 and 4 are the ones you need.

John F Hall (Mr)
[Retired academic survey researcher]

Email:   [hidden email]  
Website: www.surveyresearch.weebly.com
SPSS start page:
www.surveyresearch.weebly.com/1-survey-analysis-workshop




-----Original Message-----

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
Of Maria Suchard
Sent: 23 August 2016 21:00
To: [hidden email]
Subject: Re: DO IF + COMPUTE Command not computing all statements SPSS
v.23

Thank you, David. I am reviewing that now.



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/DO-IF-COMPUTE-Command-no
t-computing-all-statements-SPSS-v-23-tp5732961p5732964.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: DO IF + COMPUTE Command not computing all statements SPSS v.23

Maria Suchard
In reply to this post by David Marso
Thank you for code the suggestion.  I tried running the suggested code and I still found that if: "AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1." is not accounting for ENTER1ST=0 and ENTERCUR=1, still codes as NORMSTAT=2, not NORMSTAT=1. I don't understand why. Would it be better to separate out the code into two separate statements? Thank you again.

Copy of David's suggested code
RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
COMPUTE NORMSTAT=2.

IF ANY (SEX,1,2)
   AND ENRLSTAT=3
   AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1.
IF MISSING(NORMSTAT) NORMSTAT=2.
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).

Maria Suggested Alteration
RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
COMPUTE NORMSTAT=2.
IF ANY (SEX,1,2) AND (ENRLSTAT=3 AND ENTER1ST=1) NORMSTAT=1.
IF ANY (SEX,1,2) AND (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1.
IF MISSING(NORMSTAT) NORMSTAT=2.
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

David Marso
Administrator


On Wed, Aug 24, 2016 at 1:09 PM, Maria Suchard [via SPSSX Discussion] <[hidden email]> wrote:
Thank you for code the suggestion.  I tried running the suggested code and I still found that if: "AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1." is not accounting for ENTER1ST=0 and ENTERCUR=1, still codes as NORMSTAT=2, not NORMSTAT=1. I don't understand why. Would it be better to separate out the code into two separate statements? Thank you again.

Copy of David's suggested code
RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
COMPUTE NORMSTAT=2.

IF ANY (SEX,1,2)
   AND ENRLSTAT=3
   AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1.
IF MISSING(NORMSTAT) NORMSTAT=2.
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).

Maria Suggested Alteration
RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
COMPUTE NORMSTAT=2.
IF ANY (SEX,1,2) AND (ENRLSTAT=3 AND ENTER1ST=1) NORMSTAT=1.
IF ANY (SEX,1,2) AND (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1.
IF MISSING(NORMSTAT) NORMSTAT=2.
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).


To unsubscribe from DO IF + COMPUTE Command not computing all statements SPSS v.23, click here.
NAML

Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

David Marso
Administrator
In reply to this post by Maria Suchard
Your suggested modification does not have the same logical consequences as your original code.
Note in the original "ENRLSTAT=3" is distributed conjunctively to both disjuncts.  
In your revision it will only apply to the first.
A & (B | C) = A & B | A & C

Build an exhaustive table of the possible values of your SEX, ENRLSTAT, ENTER1ST and ENTERCUR variables along with the desired values of NORMSTAT.  Don't know what values ENRLSTAT can take or what these variables represent. say 2 values of sex, 3? values of ENRLSTAT, 2 each for ENTER1ST and ENTERCUR  will give you 24 possible combinations.

Maria Suchard wrote
Thank you for code the suggestion.  I tried running the suggested code and I still found that if: "AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1." is not accounting for ENTER1ST=0 and ENTERCUR=1, still codes as NORMSTAT=2, not NORMSTAT=1. I don't understand why. Would it be better to separate out the code into two separate statements? Thank you again.

Copy of David's suggested code
RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
COMPUTE NORMSTAT=2.

IF ANY (SEX,1,2)
   AND ENRLSTAT=3
   AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1.
IF MISSING(NORMSTAT) NORMSTAT=2.
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).

Maria Suggested Alteration
RECODE ENTER1ST ENTERCUR (MISSING=0)(ELSE=COPY).
COMPUTE NORMSTAT=2.
IF ANY (SEX,1,2) AND (ENRLSTAT=3 AND ENTER1ST=1) NORMSTAT=1.
IF ANY (SEX,1,2) AND (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1.
IF MISSING(NORMSTAT) NORMSTAT=2.
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

Maria Suchard
Yes, you're correct. I forgot the ENRLSTAT=3 statement. I have built out the table and looking at that now. You mentioned something in a prior thread "MISSING VALUES command done after IF". Can you tell me why this is important? I did the follow up reading you mentioned about missing values, but I am not clear on if adding missing values at the end of the statement- what affect this has on either the statement itself or how it is carried out?

Thanks again.
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

Rick Oliver
User-defined missing values are not treated as missing until you define them as missing.
IF and DO IF do not process user-missing values. That is, a condition based on a value declared as missing is always treated as false -- unless you use the VALUE function.

Your original example contained something equivalent to:

missing values x (0).
do if x=0.
[do something]
end if.

This condition will never be met because 0 is defined as missing.

If you reverse the order of operation, it would work the first time:

do if x=0.
[do something]
end if.
missing values x (0).

But this solution only works once, since subsequently 0 is missing. Better solution:

missing values x (0).
do if value(x)=0.
[do something]
end if.

The VALUE function tells the application to treat 0 as valid even if it is defined as missing.

On Wed, Aug 24, 2016 at 1:06 PM, Maria Suchard <[hidden email]> wrote:
Yes, you're correct. I forgot the ENRLSTAT=3 statement. I have built out the
table and looking at that now. You mentioned something in a prior thread
"MISSING VALUES command done after IF". Can you tell me why this is
important? I did the follow up reading you mentioned about missing values,
but I am not clear on if adding missing values at the end of the statement-
what affect this has on either the statement itself or how it is carried
out?

Thanks again.



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/DO-IF-COMPUTE-Command-not-computing-all-statements-SPSS-v-23-tp5732961p5732975.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: DO IF + COMPUTE Command not computing all statements SPSS v.23

Jon Peck
Strictly speaking, the statement
"That is, a condition based on a value declared as missing is always treated as false -- unless you use the VALUE function."
is false.
Rather, the condition is treated as neither true nor false, so even with an ELSE nothing happens.

Example.  When x is 0, neither the true nor the else clause is executed, and the result is sysmis.
compute x = rv.poisson(2).
missing values x(0).
do if x=0.
compute y = 99.
ELSE.
compute y = 999.
end if.
exec.

On Wed, Aug 24, 2016 at 1:08 PM, Rick Oliver <[hidden email]> wrote:
User-defined missing values are not treated as missing until you define them as missing.
IF and DO IF do not process user-missing values. That is, a condition based on a value declared as missing is always treated as false -- unless you use the VALUE function.

Your original example contained something equivalent to:

missing values x (0).
do if x=0.
[do something]
end if.

This condition will never be met because 0 is defined as missing.

If you reverse the order of operation, it would work the first time:

do if x=0.
[do something]
end if.
missing values x (0).

But this solution only works once, since subsequently 0 is missing. Better solution:

missing values x (0).
do if value(x)=0.
[do something]
end if.

The VALUE function tells the application to treat 0 as valid even if it is defined as missing.

On Wed, Aug 24, 2016 at 1:06 PM, Maria Suchard <[hidden email]> wrote:
Yes, you're correct. I forgot the ENRLSTAT=3 statement. I have built out the
table and looking at that now. You mentioned something in a prior thread
"MISSING VALUES command done after IF". Can you tell me why this is
important? I did the follow up reading you mentioned about missing values,
but I am not clear on if adding missing values at the end of the statement-
what affect this has on either the statement itself or how it is carried
out?

Thanks again.



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/DO-IF-COMPUTE-Command-not-computing-all-statements-SPSS-v-23-tp5732961p5732975.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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



--
Jon K Peck
[hidden email]

===================== 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: DO IF + COMPUTE Command not computing all statements SPSS v.23

David Marso
Administrator
In reply to this post by Maria Suchard
Maria Suchard wrote
Yes, you're correct. I forgot the ENRLSTAT=3 statement. I have built out the table and looking at that now. You mentioned something in a prior thread "MISSING VALUES command done after IF". Can you tell me why this is important? I did the follow up reading you mentioned about missing values, but I am not clear on if adding missing values at the end of the statement- what affect this has on either the statement itself or how it is carried out?

Thanks again.
DATA LIST FREE /SEX ENRLSTAT ENTER1ST ENTERCUR .
BEGIN DATA
1 1 0 0   1 1 0 1   1 1 1 0   1 1 1 1   1 3 0 0   1 3 0 1   1 3 1 0    1 3 1 1  
2 1 0 0   2 1 0 1   2 1 1 0   2 1 1 1   2 3 0 0   2 3 0 1   2 3 1 0    2 3 1 1  
END DATA.

/* Version 1 */.
IF ANY (SEX,1,2)
   AND ENRLSTAT=3
   AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT=1.
IF MISSING(NORMSTAT) NORMSTAT=2.
/* The following EXECUTE is *NECESSARY* */.
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).

/* Version 2 */.
/* Does NOT work as one's intuition would expect */.
/* See Help topic on MISSING VALUES and the discussion of COMMAND ORDER */.
MISSING VALUES ALL ().
IF ANY (SEX,1,2)
   AND ENRLSTAT=3
   AND (ENTER1ST=1 OR (ENTER1ST=0 AND ENTERCUR=1)) NORMSTAT2=1.
IF MISSING(NORMSTAT) NORMSTAT2=2.
MISSING VALUES ENTER1ST ENTERCUR (0).

/* Version 3 */.
/* Assuming we have values 0 and 1 in our source fields */.
/* WE can replace the logical operators AND with *, OR with + */.
MISSING VALUES ALL ().
COMPUTE NORMSTAT3=ANY(SEX,1,2)*(ENRLSTAT EQ 3)*SUM((ENTER1ST EQ 1),(ENTER1ST EQ 0)*(ENTERCUR EQ 1) ).
RECODE NORMSTAT3 (0=2).
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).

/* Version 4 */.
MISSING VALUES ALL ().
COMPUTE NORMSTAT4=ANY(SEX,1,2)*(ENRLSTAT EQ 3)*ANY(1,ENTER1ST,ENTERCUR).
RECODE NORMSTAT4 (0=2).
EXECUTE.
MISSING VALUES ENTER1ST ENTERCUR (0).
LIST.

 SEX ENRLSTAT ENTER1ST ENTERCUR NORMSTAT NORMSTAT2 NORMSTAT3 NORMSTAT4
 
    1.00     1.00      .00      .00     2.00       .        2.00      2.00
    1.00     1.00      .00     1.00     2.00       .        2.00      2.00
    1.00     1.00     1.00      .00     2.00       .        2.00      2.00
    1.00     1.00     1.00     1.00     2.00       .        2.00      2.00
    1.00     3.00      .00      .00     2.00       .        2.00      2.00
    1.00     3.00      .00     1.00     1.00      1.00      1.00      1.00
    1.00     3.00     1.00      .00     1.00      1.00      1.00      1.00
    1.00     3.00     1.00     1.00     1.00      1.00      1.00      1.00
    2.00     1.00      .00      .00     2.00       .        2.00      2.00
    2.00     1.00      .00     1.00     2.00       .        2.00      2.00
    2.00     1.00     1.00      .00     2.00       .        2.00      2.00
    2.00     1.00     1.00     1.00     2.00       .        2.00      2.00
    2.00     3.00      .00      .00     2.00       .        2.00      2.00
    2.00     3.00      .00     1.00     1.00      1.00      1.00      1.00
    2.00     3.00     1.00      .00     1.00      1.00      1.00      1.00
    2.00     3.00     1.00     1.00     1.00      1.00      1.00      1.00
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

Richard Ristow
In reply to this post by Maria Suchard
I haven't been following this thread, so this may be redundant, but


At Aug 24, 2016 3:08 PM,  Rick Oliver wrote,

IF and DO IF do not process user-missing values. That is, a condition based on a value declared as missing is always treated as false -- unless you use the VALUE function. 

That is correct as it applies to the present case, but it's not quite correct in general.


If the conditional expression on a DO IF evaluates to missing (e.g., DO IF X EQ 3, when X takes on any user-missing value), DO IF treats it as *missing*, not as *false*. The difference is that if DO IF encounters a *false* value, the next following ELSE IF or ELSE is executed (it there is one); if it encounters a *missing* value, subsequent ELSE IF and ELSE statements are ignored.


I have long argued that this is a deficiency in SPSS. It certainly has confused many users whose DO IF/END IF constructs have done nothing, with no indication of trouble, even though an ELSE IF or ELSE was there to be executed.


The simplest correction that I can see is to retain SPSS's convention that a conditional expression may have values 'true', 'false', or 'missing'; and when the required condition on an IF, DO IF, ELSE IF, LOOP IF, or END LOOP IF evaluates to missing, issue a warning.

===================== 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: DO IF + COMPUTE Command not computing all statements SPSS v.23

David Marso
Administrator
In reply to this post by David Marso
/* An example from the Syntax Reference */.
Subtle stuff that can bite you on the butt!!!
---
DATA LIST FREE / expense.
BEGIN DATA
1 0 99
END DATA.
COMPUTE income=666.
DO IF expense = 0.
- COMPUTE profit=-99.
- MISSING VALUES expense (0).
ELSE.
- COMPUTE profit=income-expense.
END IF.
LIST VARIABLES=expense profit.
 
 expense   profit
 
    1.00   665.00
     .00      .
   99.00   567.00

/* Say what */.
COMPUTE precedes MISSING VALUES and is processed first; however, execution is delayed until the data are read.
•MISSING VALUES takes effect as soon as it is encountered, even if the condition is never met (i.e., even if there are no cases where expense=0).
•LIST causes the data to be read; thus, both COMPUTE and LIST are executed during the same data pass.
•Because MISSING VALUES is already in effect by this time, the first condition in the DO IF structure will never be met, because an expense value of 0 is considered missing and so the condition evaluates to missing when expense is 0.

Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

Maria Suchard
Thank you! I have gone through your examples in your prior post and in going through this  latest post your explanation makes total sense. And I will do reading on MISSING VALUES and COMMAND ORDER. Thank you again. I can take it from here.
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

Maria Suchard
In reply to this post by Jon Peck
Thank you Rick and Jon. This is very helpful.

My question is this: when assigning a missing value to zero (0) or any other number, and placing this statement at the beginning of the syntax that I am wanting to execute- then asking SPSS to perform a function based on that missing value will results in sysmis. Is this correct? In looking up assigning missing values in SPSS many of the examples that I see does place the missing values statement at the beginning of the syntax. But that syntax is defining a different missing value then NOT asking SPSS to "do something" with that value. Am I on the right track? I am fundamentally trying to understand best practice about how SPSS will read the statement/function as a whole and execute it.

With appreciation.
Reply | Threaded
Open this post in threaded view
|

Re: DO IF + COMPUTE Command not computing all statements SPSS v.23

Rick Oliver
As has been previously noted by others, if x=0 and 0 is defined as missing, then the expression do if x=0 evaluates to missing, which means the condition is never met. If the result variable is numeric, no other conditions are met, and the result variable has not been previously set to some value, then the value of the result variable will be sysmis.

data list free /x.
begin data
1 2 3 0
end data.
missing value x (0).
*y not previously set to anything.
*z is initialized to 0.
compute z=0.
do if x=0.
compute y=1.
compute z=1.
end if.
*y is sysmis, z is still 0.
list.



12