I am an SPSS newbie(just 2/3 days of learning) trying to write a
syntax file. My data file "sample.sav" contains variables like
ceq1 ceq2 ceq3 ...... ceq24 ceqsum1 ceqsum
8 0 1 2
0 2 1 1
1 2 0 8
I need to calculate
1) ceqsum1: sum of all the 1's for a give row.
2) ceqsum: sum of all ceq items for a given row
In my syntax file I do the following:
GET FILE='sample.sav' /KEEP=ceq1 TO ceq24.
COMPUTE ceqsum1=0.
* Compute sum
VECTOR k=ceq1 TO ceq24.
+ LOOP #i=1 TO 24.
+ IF (k(#i) EQ 1) ceqsum1=ceqsum1+k(#i).
+ END LOOP.
EXECUTE.
* Compute distribution
COMPUTE ceqsum = SUM(ceq1 TO ceq24) .
EXECUTE .
*END PROGRAM.
when I run the syntax file, "ceqsum" is properly calculated, however
"ceqsum1" calculation is failing. I am getting the following error:
>Error # 4023 in column 8. Text: k
>An expression contains a string of characters followed by a left
>parenthesis, indicating that the string of characters is a function
or
>vector name, but the characters do not match any existing function or
>vector. Check the spelling.
>This command not executed.
I have hours searching newsgroups, SPSS syntax help guide, and other
internet help tutorials(including commonly referred Raynald's website
http://pages.infinit.net/rlevesqu/index.htm), but I am unable to
figure out why my variable vector "k" defination is invalid.
Anybody can help me in this regard.
thanks
ruben
While there may be other errors, I notice above that you do not
have a "." at the end of your comment line "* Compute sum". This will
cause SPSS to interpret the next line, with the Vector declaration,
as a comment also. Then, when you try to use the vector, SPSS
does not recognize it. (Once a comment is initiated with "*," SPSS
assumes the comment continues until the end of the statment,
not the end of the line.)
Also, although your code may work with this correction, a vector
is not necessary to count the number of 1s.
You can just use the COUNT procedure:
count ceqsum1 = ceq1 to ceq24(1) .
Regards,
--
=-=-=-=-=-=-=-=-=-==-=-=-=
Mike Lacy, Ft Collins CO 80523
Clean out the 'junk' to email me.
compute ceqsum = sum(ceq01 to ceq24).
if there are random items with missing values and at least 20 have valid
scores.
compute n_ok = nvalid (ceq01 to ceq24).
compute ceqsum = sum.20(ceq01 to ceq24) * (24/n_ok).
is easier.
Art
A...@DrKendall.org
Social Research Consultants
University Park, MD USA
(301) 864-5570