Basic Conditional Compute Syntax

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

Basic Conditional Compute Syntax

Jim Moffitt
I have three existing numeric variables, Q1, Q2, and Q3.
How do I write the syntax to give Q3 a value of 1 if Q1=1 and Q2=1, and
give Q3 a value of 0 if Q1 and Q2 contain any other combination of
values or system missing?
 
Examples:
If Q1=1 and Q2=1, Q3 should =1.
If Q1=6 and Q2=1, Q3 should =0.
If Q1=system missing and Q2=1, Q3 should =0.
If Q1=system missing and Q2=system missing, Q3 should =0.

====================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: Basic Conditional Compute Syntax

Oliver, Richard
Evaluate missing values first:

do if missing(q1) or missing(q2).
compute q3=0.
else if q1=1 & q2=1.
compute q3=1.
else.
compute q3=0.
end if.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jim Moffitt
Sent: Friday, November 30, 2007 1:50 PM
To: [hidden email]
Subject: Basic Conditional Compute Syntax

I have three existing numeric variables, Q1, Q2, and Q3.
How do I write the syntax to give Q3 a value of 1 if Q1=1 and Q2=1, and
give Q3 a value of 0 if Q1 and Q2 contain any other combination of
values or system missing?

Examples:
If Q1=1 and Q2=1, Q3 should =1.
If Q1=6 and Q2=1, Q3 should =0.
If Q1=system missing and Q2=1, Q3 should =0.
If Q1=system missing and Q2=system missing, Q3 should =0.

=======
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: Basic Conditional Compute Syntax

Jim Moffitt
Thanks, Richard.

-----Original Message-----
From: Oliver, Richard [mailto:[hidden email]]
Sent: Friday, November 30, 2007 2:39 PM
To: Moffitt, James (West); [hidden email]
Subject: RE: Basic Conditional Compute Syntax

Evaluate missing values first:

do if missing(q1) or missing(q2).
compute q3=0.
else if q1=1 & q2=1.
compute q3=1.
else.
compute q3=0.
end if.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Jim Moffitt
Sent: Friday, November 30, 2007 1:50 PM
To: [hidden email]
Subject: Basic Conditional Compute Syntax

I have three existing numeric variables, Q1, Q2, and Q3.
How do I write the syntax to give Q3 a value of 1 if Q1=1 and Q2=1, and
give Q3 a value of 0 if Q1 and Q2 contain any other combination of
values or system missing?

Examples:
If Q1=1 and Q2=1, Q3 should =1.
If Q1=6 and Q2=1, Q3 should =0.
If Q1=system missing and Q2=1, Q3 should =0.
If Q1=system missing and Q2=system missing, Q3 should =0.

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