IF vs DO IF

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

IF vs DO IF

C Kirkman
Why do the following "IF" statements work, but not the "DO IF"? With
the "DO IF" I do not get any values for 4 or 5. I think I'm missing
something on the "DO IF" logic. Thanks.

COMPUTE MT = 0.
IF (N48 = 1) MT =1.
IF (MetFull = 1) MT = 2.
IF (MetN*N48>1) MT = 3.
IF (MetFull*N48 = 1) MT=4.

COMPUTE MT = 0.
DO IF (N48 = 1).
COMPUTE MT =1.
ELSE IF (MetFull = 1).
COMPUTE MT = 2.
ELSE IF (MetN*N48>1).
COMPUTE MT = 3.
ELSE IF (MetFull*N48 = 1).
COMPUTE MT=4.
END IF.
Reply | Threaded
Open this post in threaded view
|

Re: IF vs DO IF

Maguin, Eugene
C.,

Your troubles are coming from the fact that you may not understand the
operation of the do if, else if structure. You should read about it in the
syntax reference. That said, in a do if structure, cases that satisfy the
first condition are not eligible for consideration for the second (and
subsequent) condition. So, those cases for which N48=1 will not be
considered for the condition netfull=1.

Gene Maguin
Reply | Threaded
Open this post in threaded view
|

Re: IF vs DO IF

Richard Ristow
At 02:57 PM 4/23/2007, Gene Maguin wrote:

>That said, in a do if structure, cases that satisfy the [any]
>condition are not eligible for consideration for [any subsequent]
>condition. So, those cases for which N48=1 will not be considered for
>the condition netfull=1.

In addition, cases where any test result is missing, will not be
eligible for consideration for any other condition. For example, in
your code, if N48 is missing, no assignments will be performed.
Reply | Threaded
Open this post in threaded view
|

Re: IF vs DO IF

C Kirkman
In reply to this post by C Kirkman
You're right--I misunderstood the structure. Thanks.