Login  Register

Re: IF statement to overwite an existing value with a missing value

Posted by Richard Ristow on Feb 09, 2007; 10:21pm
URL: http://spssx-discussion.165.s1.nabble.com/Information-about-S-curve-in-SPSS-tp1073784p1073789.html

At 03:43 PM 2/9/2007, Marks, Jim wrote:

>A statement like:
>
>COMPUTE P01_VAR3 = $SYMSIS.
>IF P01_VAR4 > 0 P01_VAR3 = P01_VAR1.
>
>Will reset all the values and populate P01_VAR3 with the values you
>want.

Touché. That's the way we did it before DO IF was
introduced. It's shorter, easier to write, and
easier to get right, than the DO IF solution I gave:

>>DO IF             ( P01_VAR4 > 0 )
>>    AND NOT MISSING( P01_VAR4 > 0 ).
>>.  COMPUTE P01_VAR3 = P01_VAR1 .
>>ELSE.
>>.  COMPUTE P01_VAR3 = $SYSMIS.
>>END IF.

There's a lot to be said for remembering old-school styles.

Jim also wrote,

>It looks like you have a set of variables to process. If so, something
>using DO REPEAT could reduce your typing:

Yes. Reduce your typing, make your code shorter
and more readable, and be less prone to errors.

-Good luck, and thanks,
  Richard