Login  Register

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

Posted by Marks, Jim on Feb 09, 2007; 8:43pm
URL: http://spssx-discussion.165.s1.nabble.com/Information-about-S-curve-in-SPSS-tp1073784p1073788.html

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.

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


*** SAMPLE DATA.

data list free /id P01_VAR4 P02_VAR4 P03_VAR4 P01_VAR1.

begin data
1 2 2 0 0 0 5
2 1 1 1 1 0 5
3 0 0 0 0 0 5
4 1 2 3 4 5 5
5 0 0 0 0 1 5
end data.


DO REPEAT
    x = P01_VAR4 P02_VAR4 P03_VAR4 P04_VAR4
   /y = P01_VAR3 P02_VAR3 P03_VAR3 P04_VAR3
.
COMPUTE Y = $SYSMIS.
IF X >0 Y =P01_VAR1.
END REPEAT.
EXE.

This will run COMPUTE for each value of Pxx_VAR4 and Pxx_VAR3.

Does this help?

--jim

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Gary Oliver
Sent: Thursday, February 08, 2007 9:57 PM
To: [hidden email]
Subject: IF statement to overwite an existing value with a missing value

Colleagues

I have the following set of IF statements which successfully execute.
IF ( P01_VAR4 > 0 ) P01_VAR3 = P01_VAR1 .
...
IF ( P35_VAR4 > 0 ) P35_VAR3 = P01_VAR1 .

In some cases the value for VAR3 is zero and I rightly get a warning
message and the cell is marked with a dot for missing value.

The command has evolved over a week of modifying the calculation with
the result that the cells contain pre-existing values. What I have
noticed is that the IF statement above does not replace the pre-existing
values with a blank cell.

My questions are:

(a) Is there a command that I can apply to a variable to clear values?

I cannot see anything in the syntax help file that
erases/deletes/removes values. These key words only seem to apply to
files or variables themselves.


(b) Is there an amendment to the syntax which can force a missing value
to be inserted overriding whatever is in the cell?

TIA/gary