Date: Mon, 19 Mar 2001 20:15:40 -0500
Reply-To: Raynald Levesque <rlevesque@VIDEOTRON.CA>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Raynald Levesque <rlevesque@VIDEOTRON.CA>
Subject: Re: Strange effect on transformations
Content-Type: text/plain; charset="us-ascii"
** You asked:
'Can someone explain please why you get DIFFERENT, WRONG answers if
temporary variables are used in the suggested VECTOR command.'
The syntax is behaving as described in the Syntax Guide. In the description
of temporary (scratch) variables, the guide states:
SPSS does not reinitialize scratch variables when reading a new case. Their
values are al-ways
carried across cases. Therefore, a scratch variable is a good choice for a
Hence when you get the second cases the values of ss which had been defined
by case 1 are still present. The only new value in case 2 is 23 (1 and 6
were already present in case 1). This explain the incorrect value of 7 you
get for the Ndiffclubs of Subj2.
When you get to Subj3 there are 3 new values. THus you get 10 as the
Finally there are no new values with Subj4. Thus the answer remains 10 for
the last case.
** You asked:
'is there any way to use VECTOR in a transformation such as COUNT? The
parser does not recognise the vector name, so the command
count nsports = ss(1) to ss(55) (1).'
You can use:
count nsports=ss1 to ss55 (1).
Raynald Levesque firstname.lastname@example.org
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of
R. Allan Reese
Sent: Monday, March 19, 2001 10:28 AM
Subject: Strange effect on transformations
I offered an answer to how to compute the column Ndiffclubs in the following
data, but found a strange effect in SPSS syntax. Can someone
explain please why you get DIFFERENT, WRONG answers if temporary variables
are used in the suggested VECTOR command.
1) Problem - how to count number of distinct values in row:
Sport1 Sport2 Sport3 Sport4 Sport5 Sport6 Ndiffclubs
Subj1 1 5 6 7 30 12 6
Subj2 1 1 23 6 3
Subj3 3 7 45 45 15 4
Subj4 6 6 12 12 2
2) Suggested solution:
Use VECTOR to generate 55 new variables, which can be temporary:
do repeat sport=sport1 to sport6.
if (sport>0 and sport<56) ss(sport)=1.
loop #N=1 to 55.
if ( ss(#N) = 1 ) nsports=nsports+1.
EXCEPT: when I add a # in front of SS, I get different, and wrong, answers.
So use this code and drop ss1 to ss55 when you save the file.
3) A related question: is there any way to use VECTOR in a transformation
such as COUNT? The parser does not recognise the vector name, so the
count nsports = ss(1) to ss(55) (1).
fails because it wants ss to be a variable and (1) to be its value.
R. Allan Reese Email: email@example.com