Arithmetic function and missings

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

Arithmetic function and missings

Tom

Hello

 

Computing a new variable I’d like to calculate only the valid values, without the missings (values -1 and -9 are defined as missings).

 

I thought that SPSS takes this into account automatically, but it doesn’t look like:

 

data list test1 test2 test3 teststd1 teststd2 teststd3.
begin data.

2.00       4.00       1.00       6.00       3.00

3.00       4.00       -9.00      8.00       8.00

-9.00      -9.00      -9.00      -9.00      -9.00

4.00       -1.00      -1.00      16.00     -1.00.

End data.

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

That gives the following results:

2.00       4.00       1.00       6.00       3.00       12.00     36.00

3.00       4.00       -9.00      8.00       8.00       -9.00     

-9.00      -9.00      -9.00      -9.00      -9.00      -9.00     

4.00       -1.00      -1.00      16.00     -1.00      -1.00     

 

Those cases with missing values are not calculated. What should I change in the syntax?

 

Thank you very much for your help.

Tom

Reply | Threaded
Open this post in threaded view
|

AW: Arithmetic function and missings

la volta statistics

 

Hello Thomas

 

I think this is the command you are looking for.

 

compute totaltest =sum.1(test1, test2, test3, teststd1, teststd2, teststd3).

 

The ".1" specifies the minimum number of non-missing values required.

 

Hope this helps,

Christian

 

**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Im Gubel 29
CH-8706 Feldmeilen
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
[hidden email] 
Web:
www.lavolta.ch

 

 

Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von Balmer, Thomas
Gesendet: Freitag, 16. August 2013 11:01
An: [hidden email]
Betreff: Arithmetic function and missings

 

Hello

 

Computing a new variable I’d like to calculate only the valid values, without the missings (values -1 and -9 are defined as missings).

 

I thought that SPSS takes this into account automatically, but it doesn’t look like:

 

data list test1 test2 test3 teststd1 teststd2 teststd3.
begin data.

2.00       4.00       1.00       6.00       3.00

3.00       4.00       -9.00      8.00       8.00

-9.00      -9.00      -9.00      -9.00      -9.00

4.00       -1.00      -1.00      16.00     -1.00.

End data.

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

That gives the following results:

2.00       4.00       1.00       6.00       3.00       12.00     36.00

3.00       4.00       -9.00      8.00       8.00       -9.00     

-9.00      -9.00      -9.00      -9.00      -9.00      -9.00     

4.00       -1.00      -1.00      16.00     -1.00      -1.00     

 

Those cases with missing values are not calculated. What should I change in the syntax?

 

Thank you very much for your help.

Tom

Reply | Threaded
Open this post in threaded view
|

Re: Arithmetic function and missings

John F Hall
In reply to this post by Tom

You’ve omitted the keyword FREE / and not declared any missing values.  You’ve declared 6 variables, but only given data for 5.   You also have a period after begin data: it’s optional, but the manual recommends leaving it out.

 

I’ve added some more data for the 6th variable and checked that the syntax works.  Teststd3 comes out as nominal, but you can change that to SCALE.

 

If you only have a small amount of data, you might be better entering it direct into the Data Editor.

 

 

John F Hall (Mr)

[Retired academic survey researcher]

 

Email:   [hidden email] 

Website: www.surveyresearch.weebly.com

SPSS start page:  www.surveyresearch.weebly.com/spss-without-tears.html

  

  

 

 

 

 


data list free / test1 test2 test3 teststd1 teststd2 teststd3.

 

begin data

2.00       4.00       1.00       6.00       3.00    1.0

3.00       4.00       -9.00      8.00       8.00   1.0

-9.00      -9.00      -9.00      -9.00      -9.00  1.0

4.00       -1.00      -1.00      16.00     -1.00    1.0

End data.

 

missing values test1 to teststd3 (-1).

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Balmer, Thomas
Sent: 16 August 2013 11:01
To: [hidden email]
Subject: Arithmetic function and missings

 

Hello

 

Computing a new variable I’d like to calculate only the valid values, without the missings (values -1 and -9 are defined as missings).

 

I thought that SPSS takes this into account automatically, but it doesn’t look like:

 

data list test1 test2 test3 teststd1 teststd2 teststd3.
begin data.

2.00       4.00       1.00       6.00       3.00

3.00       4.00       -9.00      8.00       8.00

-9.00      -9.00      -9.00      -9.00      -9.00

4.00       -1.00      -1.00      16.00     -1.00.

End data.

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

That gives the following results:

2.00       4.00       1.00       6.00       3.00       12.00     36.00

3.00       4.00       -9.00      8.00       8.00       -9.00     

-9.00      -9.00      -9.00      -9.00      -9.00      -9.00     

4.00       -1.00      -1.00      16.00     -1.00      -1.00     

 

Those cases with missing values are not calculated. What should I change in the syntax?

 

Thank you very much for your help.

Tom

Reply | Threaded
Open this post in threaded view
|

Re: Arithmetic function and missings

John F Hall

Silly mistake: I left -9 out of missing values.  Herewith revised syntax:

 

data list free / test1 test2 test3 teststd1 teststd2 teststd3.

 

begin data

2.00       4.00       1.00       6.00       3.00    1.0

3.00       4.00       -9.00      8.00       8.00   1.0

-9.00      -9.00      -9.00      -9.00      -9.00  1.0

4.00       -1.00      -1.00      16.00     -1.00    1.0

End data.

 

missing values test1 to teststd3 (-1,-9).

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

Data generated as follows:

 

2.00      4.00      1.00      6.00      3.00      1.00      25.00

3.00      4.00      -9.00    8.00      8.00      1.00     

-9.00    -9.00    -9.00    -9.00    -9.00    1.00     

4.00      -1.00    -1.00    16.00    -1.00    1.00     

 

 

John F Hall (Mr)

[Retired academic survey researcher]

 

Email:   [hidden email] 

Website: www.surveyresearch.weebly.com

SPSS start page:  www.surveyresearch.weebly.com/spss-without-tears.html

  

  

 

 

 

 

From: John F Hall [mailto:[hidden email]]
Sent: 16 August 2013 11:59
To: [hidden email]
Subject: RE: Arithmetic function and missings

 

You’ve omitted the keyword FREE / and not declared any missing values.  You’ve declared 6 variables, but only given data for 5.   You also have a period after begin data: it’s optional, but the manual recommends leaving it out.

 

I’ve added some more data for the 6th variable and checked that the syntax works.  Teststd3 comes out as nominal, but you can change that to SCALE.

 

If you only have a small amount of data, you might be better entering it direct into the Data Editor.

 

 

John F Hall (Mr)

[Retired academic survey researcher]

 

Email:   [hidden email] 

Website: www.surveyresearch.weebly.com

SPSS start page:  www.surveyresearch.weebly.com/spss-without-tears.html

  

  

 

 

 

 


data list free / test1 test2 test3 teststd1 teststd2 teststd3.

 

begin data

2.00       4.00       1.00       6.00       3.00    1.0

3.00       4.00       -9.00      8.00       8.00   1.0

-9.00      -9.00      -9.00      -9.00      -9.00  1.0

4.00       -1.00      -1.00      16.00     -1.00    1.0

End data.

 

missing values test1 to teststd3 (-1).

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Balmer, Thomas
Sent: 16 August 2013 11:01
To: [hidden email]
Subject: Arithmetic function and missings

 

Hello

 

Computing a new variable I’d like to calculate only the valid values, without the missings (values -1 and -9 are defined as missings).

 

I thought that SPSS takes this into account automatically, but it doesn’t look like:

 

data list test1 test2 test3 teststd1 teststd2 teststd3.
begin data.

2.00       4.00       1.00       6.00       3.00

3.00       4.00       -9.00      8.00       8.00

-9.00      -9.00      -9.00      -9.00      -9.00

4.00       -1.00      -1.00      16.00     -1.00.

End data.

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

That gives the following results:

2.00       4.00       1.00       6.00       3.00       12.00     36.00

3.00       4.00       -9.00      8.00       8.00       -9.00     

-9.00      -9.00      -9.00      -9.00      -9.00      -9.00     

4.00       -1.00      -1.00      16.00     -1.00      -1.00     

 

Those cases with missing values are not calculated. What should I change in the syntax?

 

Thank you very much for your help.

Tom

Tom
Reply | Threaded
Open this post in threaded view
|

AW: Arithmetic function and missings

Tom

The results are still not as espected (the 6. Var. in your results are not as originally ;-)):

 

2.00       4.00       1.00       6.00       3.00       12.00     36.00

3.00       4.00       -9.00      8.00       8.00       -9.00     

-9.00      -9.00      -9.00      -9.00      -9.00      -9.00     

4.00       -1.00      -1.00      16.00     -1.00      -1.00     

 

Case 2 to 4 should have the following 7. Var: 2.: 3*8+4*8= 56; 3.: missing; 4.: 4*16=64

 

 

 

 

Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von John F Hall
Gesendet: Freitag, 16. August 2013 12:25
An: [hidden email]
Betreff: Re: Arithmetic function and missings

 

Silly mistake: I left -9 out of missing values.  Herewith revised syntax:

 

data list free / test1 test2 test3 teststd1 teststd2 teststd3.

 

begin data

2.00       4.00       1.00       6.00       3.00    1.0

3.00       4.00       -9.00      8.00       8.00   1.0

-9.00      -9.00      -9.00      -9.00      -9.00  1.0

4.00       -1.00      -1.00      16.00     -1.00    1.0

End data.

 

missing values test1 to teststd3 (-1,-9).

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

Data generated as follows:

 

2.00      4.00      1.00      6.00      3.00      1.00      25.00

3.00      4.00      -9.00     8.00      8.00      1.00     

-9.00     -9.00     -9.00     -9.00     -9.00     1.00     

4.00      -1.00     -1.00     16.00    -1.00     1.00     

 

 

John F Hall (Mr)

[Retired academic survey researcher]

 

Email:   [hidden email] 

Website: www.surveyresearch.weebly.com

SPSS start page:  www.surveyresearch.weebly.com/spss-without-tears.html

  

  

 

 

 

 

From: John F Hall [[hidden email]]
Sent: 16 August 2013 11:59
To: [hidden email]
Subject: RE: Arithmetic function and missings

 

You’ve omitted the keyword FREE / and not declared any missing values.  You’ve declared 6 variables, but only given data for 5.   You also have a period after begin data: it’s optional, but the manual recommends leaving it out.

 

I’ve added some more data for the 6th variable and checked that the syntax works.  Teststd3 comes out as nominal, but you can change that to SCALE.

 

If you only have a small amount of data, you might be better entering it direct into the Data Editor.

 

 

John F Hall (Mr)

[Retired academic survey researcher]

 

Email:   [hidden email] 

Website: www.surveyresearch.weebly.com

SPSS start page:  www.surveyresearch.weebly.com/spss-without-tears.html

  

  

 

 

 

 


data list free / test1 test2 test3 teststd1 teststd2 teststd3.

 

begin data

2.00       4.00       1.00       6.00       3.00    1.0

3.00       4.00       -9.00      8.00       8.00   1.0

-9.00      -9.00      -9.00      -9.00      -9.00  1.0

4.00       -1.00      -1.00      16.00     -1.00    1.0

End data.

 

missing values test1 to teststd3 (-1).

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Balmer, Thomas
Sent: 16 August 2013 11:01
To: [hidden email]
Subject: Arithmetic function and missings

 

Hello

 

Computing a new variable I’d like to calculate only the valid values, without the missings (values -1 and -9 are defined as missings).

 

I thought that SPSS takes this into account automatically, but it doesn’t look like:

 

data list test1 test2 test3 teststd1 teststd2 teststd3.
begin data.

2.00       4.00       1.00       6.00       3.00

3.00       4.00       -9.00      8.00       8.00

-9.00      -9.00      -9.00      -9.00      -9.00

4.00       -1.00      -1.00      16.00     -1.00.

End data.

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

That gives the following results:

2.00       4.00       1.00       6.00       3.00       12.00     36.00

3.00       4.00       -9.00      8.00       8.00       -9.00     

-9.00      -9.00      -9.00      -9.00      -9.00      -9.00     

4.00       -1.00      -1.00      16.00     -1.00      -1.00     

 

Those cases with missing values are not calculated. What should I change in the syntax?

 

Thank you very much for your help.

Tom

Reply | Threaded
Open this post in threaded view
|

Re: AW: Arithmetic function and missings

Andy W
You should let people what how you expect the calculation to be when you first ask, not three or four responses in! Here are a couple different ways, with the do repeat generalizing to more variables more easily than the other two. I couldn't think of any other way for the third case to be set to missing and simultaneously other cases be treated as zeroes with a missing value in the pair (besides evaluating after the fact).

**********************************************.
data list free / test1 test2 test3 teststd1 teststd2 teststd3.
begin data
2.00       4.00       1.00       6.00       3.00    1.0
3.00       4.00       -9.00      8.00       8.00   1.0
-9.00      -9.00      -9.00      -9.00      -9.00  1.0
4.00       -1.00      -1.00      16.00     -1.00    1.0
End data.
missing values test1 to teststd3 (-1,-9).
exe.

*do repeat way.
compute totaltest = 0.
compute #mis1 = 0.
compute #mis2 = 0.
do repeat test = test1 to test3 /teststd = teststd1 to teststd3.
do if MISSING(test) = 0 and MISSING(teststd) = 0.
    compute totaltest = totaltest + test*teststd.
end if.
compute #mis1 = #mis1 + MISSING(test).
compute #mis2 = #mis2 + MISSING(teststd).
end repeat.
if #mis1 = 3 or #mis2 = 3 totaltest = $SYSMIS.
exe.

*recode way.
recode test1 to test3 (-1,-9 = 0)(ELSE = COPY) into #t1 to #t3.
recode teststd1 to teststd3 (-1,-9 = 0)(ELSE = COPY) into #td1 to #td3.
compute totaltest2 = #t1*#td1 + #t2*#td2 + #t3*#td3.
compute #mis1 = MISSING(test1) + MISSING(test2) + MISSING(test3).
compute #mis2 = MISSING(teststd1) + MISSING(teststd2) + MISSING(teststd3).
if #mis1 = 3 or #mis2 = 3 totaltest2 = $SYSMIS.
exe.

*sum way.
compute totaltest3 = SUM(test1,0)*SUM(teststd1,0) + SUM(test2,0)*SUM(teststd2,0) + SUM(test3,0)*SUM(teststd3,0).
compute #mis1 = MISSING(test1) + MISSING(test2) + MISSING(test3).
compute #mis2 = MISSING(teststd1) + MISSING(teststd2) + MISSING(teststd3).
if #mis1 = 3 or #mis2 = 3 totaltest2 = $SYSMIS.
exe.
**********************************************.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Arithmetic function and missings

Maguin, Eugene
In reply to this post by Tom

Here’s another variation, that I absolutely would have bet would not work, but does.

 

 

data list free / test1 test2 test3 teststd1 teststd2 teststd3.

begin data

2.00       4.00       1.00       6.00       3.00    1.0

3.00       4.00       -9.00      8.00       8.00   1.0

-9.00      -9.00      -9.00      -9.00      -9.00  1.0

4.00       -1.00      -1.00      16.00     -1.00    1.0

End data.

execute.

compute y=sum.1(test1*teststd1,test2*teststd2,test3*teststd3).

list y test1 teststd1 test2 teststd2 test3 teststd3.

 

     y  test1 teststd1  test2 teststd2  test3 teststd3

 

25.00   2.00    6.00    4.00    3.00    1.00    1.00

47.00   3.00    8.00    4.00    8.00   -9.00    1.00

153.00  -9.00   -9.00   -9.00   -9.00   -9.00    1.00

64.00   4.00   16.00   -1.00   -1.00   -1.00    1.00

 

 

Number of cases read:  4    Number of cases listed:  4

 

 

 

 

 

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Balmer, Thomas
Sent: Friday, August 16, 2013 7:30 AM
To: [hidden email]
Subject: AW: Arithmetic function and missings

 

The results are still not as espected (the 6. Var. in your results are not as originally ;-)):

 

2.00       4.00       1.00       6.00       3.00       12.00     36.00

3.00       4.00       -9.00      8.00       8.00       -9.00     

-9.00      -9.00      -9.00      -9.00      -9.00      -9.00     

4.00       -1.00      -1.00      16.00     -1.00      -1.00     

 

Case 2 to 4 should have the following 7. Var: 2.: 3*8+4*8= 56; 3.: missing; 4.: 4*16=64

 

 

 

 

Von: SPSSX(r) Discussion [[hidden email]] Im Auftrag von John F Hall
Gesendet: Freitag, 16. August 2013 12:25
An: [hidden email]
Betreff: Re: Arithmetic function and missings

 

Silly mistake: I left -9 out of missing values.  Herewith revised syntax:

 

data list free / test1 test2 test3 teststd1 teststd2 teststd3.

 

begin data

2.00       4.00       1.00       6.00       3.00    1.0

3.00       4.00       -9.00      8.00       8.00   1.0

-9.00      -9.00      -9.00      -9.00      -9.00  1.0

4.00       -1.00      -1.00      16.00     -1.00    1.0

End data.

 

missing values test1 to teststd3 (-1,-9).

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

Data generated as follows:

 

2.00      4.00      1.00      6.00      3.00      1.00      25.00

3.00      4.00      -9.00     8.00      8.00      1.00     

-9.00     -9.00     -9.00     -9.00     -9.00     1.00     

4.00      -1.00     -1.00     16.00    -1.00     1.00     

 

 

John F Hall (Mr)

[Retired academic survey researcher]

 

Email:   [hidden email] 

Website: www.surveyresearch.weebly.com

SPSS start page:  www.surveyresearch.weebly.com/spss-without-tears.html

  

  

 

 

 

 

From: John F Hall [[hidden email]]
Sent: 16 August 2013 11:59
To: [hidden email]
Subject: RE: Arithmetic function and missings

 

You’ve omitted the keyword FREE / and not declared any missing values.  You’ve declared 6 variables, but only given data for 5.   You also have a period after begin data: it’s optional, but the manual recommends leaving it out.

 

I’ve added some more data for the 6th variable and checked that the syntax works.  Teststd3 comes out as nominal, but you can change that to SCALE.

 

If you only have a small amount of data, you might be better entering it direct into the Data Editor.

 

 

John F Hall (Mr)

[Retired academic survey researcher]

 

Email:   [hidden email] 

Website: www.surveyresearch.weebly.com

SPSS start page:  www.surveyresearch.weebly.com/spss-without-tears.html

  

  

 

 

 

 


data list free / test1 test2 test3 teststd1 teststd2 teststd3.

 

begin data

2.00       4.00       1.00       6.00       3.00    1.0

3.00       4.00       -9.00      8.00       8.00   1.0

-9.00      -9.00      -9.00      -9.00      -9.00  1.0

4.00       -1.00      -1.00      16.00     -1.00    1.0

End data.

 

missing values test1 to teststd3 (-1).

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Balmer, Thomas
Sent: 16 August 2013 11:01
To: [hidden email]
Subject: Arithmetic function and missings

 

Hello

 

Computing a new variable I’d like to calculate only the valid values, without the missings (values -1 and -9 are defined as missings).

 

I thought that SPSS takes this into account automatically, but it doesn’t look like:

 

data list test1 test2 test3 teststd1 teststd2 teststd3.
begin data.

2.00       4.00       1.00       6.00       3.00

3.00       4.00       -9.00      8.00       8.00

-9.00      -9.00      -9.00      -9.00      -9.00

4.00       -1.00      -1.00      16.00     -1.00.

End data.

 

COMPUTE totaltest= test1*teststd1 + test2*teststd2 + test3*teststd3.

EXECUTE.

 

That gives the following results:

2.00       4.00       1.00       6.00       3.00       12.00     36.00

3.00       4.00       -9.00      8.00       8.00       -9.00     

-9.00      -9.00      -9.00      -9.00      -9.00      -9.00     

4.00       -1.00      -1.00      16.00     -1.00      -1.00     

 

Those cases with missing values are not calculated. What should I change in the syntax?

 

Thank you very much for your help.

Tom

Reply | Threaded
Open this post in threaded view
|

Re: AW: Arithmetic function and missings

PRogman
In reply to this post by Tom
To handle the missing values, try:

COMPUTE totaltest2= sum(test1*teststd1, test2*teststd2, test3*teststd3).
EXECUTE.

In the function Sum.n(....) the .n is the minimum number of terms to include before returning 'missing'. .3 would require all three terms and .1 would be default, I presume. See documentation on Statistical functions (COMPUTE command).

/PR
Reply | Threaded
Open this post in threaded view
|

Re: AW: Arithmetic function and missings

Andy W
Doh! Thanks for that - I'll leave my prior response up just for posterity I suppose.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Tom
Reply | Threaded
Open this post in threaded view
|

AW: AW: Arithmetic function and missings

Tom
In reply to this post by PRogman
Thanks, it works perfect!
Tom



To handle the missing values, try:

COMPUTE totaltest2= sum(test1*teststd1, test2*teststd2, test3*teststd3).
EXECUTE.

In the function Sum.n(....) the .n is the minimum number of terms to include before returning 'missing'. .3 would require all three terms and .1 would be default, I presume. See documentation on Statistical functions (COMPUTE command).

/PR



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Arithmetic-function-and-missings-tp5721597p5721605.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: AW: Arithmetic function and missings

David Marso
Administrator
In reply to this post by Andy W
"I couldn't think of any other way for the third case to be set to missing and simultaneously other cases be treated as zeroes with a missing value in the pair (besides evaluating after the fact)."
--
data list free / test1 test2 test3 teststd1 teststd2 teststd3.
begin data
2.00       4.00       1.00       6.00       3.00    1.0
3.00       4.00       -9.00      8.00       8.00   1.0
-9.00      -9.00      -9.00      -9.00      -9.00  1.0
4.00       -1.00      -1.00      16.00     -1.00    1.0
End data.
missing values test1 to teststd3 (-1,-9).

DO REPEAT test = test1 to test3 /teststd = teststd1 to teststd3.
COMPUTE totaltst=SUM(totaltst,test*teststd).
END REPEAT.
LIST.


   TEST1    TEST2    TEST3 TESTSTD1 TESTSTD2 TESTSTD3 TOTALTST

    2.00     4.00     1.00     6.00     3.00     1.00    25.00
    3.00     4.00    -9.00     8.00     8.00     1.00    56.00
   -9.00    -9.00    -9.00    -9.00    -9.00     1.00      .
    4.00    -1.00    -1.00    16.00    -1.00     1.00    64.00


Number of cases read:  4    Number of cases listed:  4


Andy W wrote
You should let people what how you expect the calculation to be when you first ask, not three or four responses in! Here are a couple different ways, with the do repeat generalizing to more variables more easily than the other two. I couldn't think of any other way for the third case to be set to missing and simultaneously other cases be treated as zeroes with a missing value in the pair (besides evaluating after the fact).

**********************************************.
data list free / test1 test2 test3 teststd1 teststd2 teststd3.
begin data
2.00       4.00       1.00       6.00       3.00    1.0
3.00       4.00       -9.00      8.00       8.00   1.0
-9.00      -9.00      -9.00      -9.00      -9.00  1.0
4.00       -1.00      -1.00      16.00     -1.00    1.0
End data.
missing values test1 to teststd3 (-1,-9).
exe.

*do repeat way.
compute totaltest = 0.
compute #mis1 = 0.
compute #mis2 = 0.
do repeat test = test1 to test3 /teststd = teststd1 to teststd3.
do if MISSING(test) = 0 and MISSING(teststd) = 0.
    compute totaltest = totaltest + test*teststd.
end if.
compute #mis1 = #mis1 + MISSING(test).
compute #mis2 = #mis2 + MISSING(teststd).
end repeat.
if #mis1 = 3 or #mis2 = 3 totaltest = $SYSMIS.
exe.

*recode way.
recode test1 to test3 (-1,-9 = 0)(ELSE = COPY) into #t1 to #t3.
recode teststd1 to teststd3 (-1,-9 = 0)(ELSE = COPY) into #td1 to #td3.
compute totaltest2 = #t1*#td1 + #t2*#td2 + #t3*#td3.
compute #mis1 = MISSING(test1) + MISSING(test2) + MISSING(test3).
compute #mis2 = MISSING(teststd1) + MISSING(teststd2) + MISSING(teststd3).
if #mis1 = 3 or #mis2 = 3 totaltest2 = $SYSMIS.
exe.

*sum way.
compute totaltest3 = SUM(test1,0)*SUM(teststd1,0) + SUM(test2,0)*SUM(teststd2,0) + SUM(test3,0)*SUM(teststd3,0).
compute #mis1 = MISSING(test1) + MISSING(test2) + MISSING(test3).
compute #mis2 = MISSING(teststd1) + MISSING(teststd2) + MISSING(teststd3).
if #mis1 = 3 or #mis2 = 3 totaltest2 = $SYSMIS.
exe.
**********************************************.
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: AW: Arithmetic function and missings

Andy W
Very cool! Thank you, I thought you would have to initialize "totaltst" to something first or SPSS would throw an error saying it doesn't exist (although thinking about it now even if that was the case you could initialize it to system missing and that DO REPEAT + SUM logic would still work).
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: AW: Arithmetic function and missings

John F Hall
In reply to this post by Andy W
Bit laborious that way.  Not at all clear what Thomas wants, but this
creates three intermediate vars as well as a total:

data list free / test1 test2 test3 teststd1 teststd2 teststd3.

begin data
2.00       4.00       1.00       6.00       3.00       12.00
-9.00      -9.00      -9.00      -9.00      -9.00      -9.00
4.00       -1.00      -1.00      16.00     -1.00      -1.00
end data.

missing values test1 to teststd3 (-1,-9).

COMPUTE x1= test1*teststd1 .
COMPUTE x2= test2*teststd2 .
COMPUTE x3= test3*teststd3.

EXECUTE.

The Data Editor then shows:

test1  test2  test3  teststd1 teststd2 teststd3  x1        x2       x3
totaltest
2.00     4.00    1.00     6.00       3.00       12.00     12.00  12.00
12.00  36.00
-9.00   -9.00   -9.00   -9.00   -9.00   -9.00
4.00    -1.00   -1.00   16.00   -1.00   -1.00   64.00
64.00

Quite what the point of this analysis I have no idea.  I assume these are
survey responses and that the original vars should be in integer format
rather than have 2 superfluous decimal places, so

formats test1 to totaltes (f2.0).

For many vars I agree that DO REPEAT would be quicker, but there are easier
ways to do it than Andy's solution.


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

Email:   [hidden email]
Website: www.surveyresearch.weebly.com
SPSS start page:  www.surveyresearch.weebly.com/spss-without-tears.html






-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Andy W
Sent: 16 August 2013 14:51
To: [hidden email]
Subject: Re: AW: Arithmetic function and missings

You should let people what how you expect the calculation to be when you
first ask, not three or four responses in! Here are a couple different ways,
with the do repeat generalizing to more variables more easily than the other
two. I couldn't think of any other way for the third case to be set to
missing and simultaneously other cases be treated as zeroes with a missing
value in the pair (besides evaluating after the fact).

**********************************************.
data list free / test1 test2 test3 teststd1 teststd2 teststd3.
begin data
2.00       4.00       1.00       6.00       3.00    1.0
3.00       4.00       -9.00      8.00       8.00   1.0
-9.00      -9.00      -9.00      -9.00      -9.00  1.0
4.00       -1.00      -1.00      16.00     -1.00    1.0
End data.
missing values test1 to teststd3 (-1,-9).
exe.

*do repeat way.
compute totaltest = 0.
compute #mis1 = 0.
compute #mis2 = 0.
do repeat test = test1 to test3 /teststd = teststd1 to teststd3.
do if MISSING(test) = 0 and MISSING(teststd) = 0.
    compute totaltest = totaltest + test*teststd.
end if.
compute #mis1 = #mis1 + MISSING(test).
compute #mis2 = #mis2 + MISSING(teststd).
end repeat.
if #mis1 = 3 or #mis2 = 3 totaltest = $SYSMIS.
exe.

*recode way.
recode test1 to test3 (-1,-9 = 0)(ELSE = COPY) into #t1 to #t3.
recode teststd1 to teststd3 (-1,-9 = 0)(ELSE = COPY) into #td1 to #td3.
compute totaltest2 = #t1*#td1 + #t2*#td2 + #t3*#td3.
compute #mis1 = MISSING(test1) + MISSING(test2) + MISSING(test3).
compute #mis2 = MISSING(teststd1) + MISSING(teststd2) + MISSING(teststd3).
if #mis1 = 3 or #mis2 = 3 totaltest2 = $SYSMIS.
exe.

*sum way.
compute totaltest3 = SUM(test1,0)*SUM(teststd1,0) +
SUM(test2,0)*SUM(teststd2,0) + SUM(test3,0)*SUM(teststd3,0).
compute #mis1 = MISSING(test1) + MISSING(test2) + MISSING(test3).
compute #mis2 = MISSING(teststd1) + MISSING(teststd2) + MISSING(teststd3).
if #mis1 = 3 or #mis2 = 3 totaltest2 = $SYSMIS.
exe.
**********************************************.



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Arithmetic-function-and-missin
gs-tp5721597p5721604.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