Date: Wed, 23 Nov 2005 12:32:04 -0500
Reply-To: emaguin@acsu.buffalo.edu
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: emaguin@acsu.buffalo.edu
Subject: Re: Sorting across variables problem
In-Reply-To: <000601c5f045$05992760$1edb17c4@Work>
Content-Type: text/plain; charset=us-ascii
Mark,
> I have 20 variables CH1 to CH20 indicating 20 choices from a list of 151
> celebrities. The order of the 151 celebs in the 20 variables are in order
> of 1st to 20th mention. I want to resort this data so that [within]
> respondents the order is increasing numerical rather than by order of
> mention. An example follows -
>
> I have -
> CH1 CH2 CH3 etc CH20
> 56 32 21 ..... 67
> 4 45 134 .... 88
> I want -
> C1 C2 C3 etc C20
> 21 32 56 ............
> 4 45 88 ...........
>
> To complicate matters a respondent doesn't have to choose 20 from the
> list - it can be less.
I wouldn't expect anything different. My proposed code for this assumes
that where less than 20 people have been listed, the remaining fields have
been recoded from sysmis to 999. (This also assumes that your celebrity
list has less than 999 names.) It also assumes that missing values are not
'turned on' for the computations. I'll assume you can do these parts. If
not, i can reply off list. I also assume that your variables, C1 to C20
are contigious.
OK.
Vector C=C1 to C20.
compute swap=0.
Loop.
+ Loop #i=1 to 19.
+ Do if (c(#i) gt c(#i+1)).
+ compute temp=c(#i).
+ compute c(#i)=c(#i+1).
+ compute c(#i+1)=temp.
+ compute swap=1.
+ End if.
+ End loop.
End loop if (swap eq 0).
There might be better ways to do this. You might want to look at Raynald
Levesque's website (Google his name).
Gene Maguin