Date: Fri, 23 Sep 2005 22:37:40 -0400
Reply-To: Richard Ristow <firstname.lastname@example.org>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Richard Ristow <email@example.com>
Subject: Re: selecting first case in a group of student records
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 10:19 AM 9/23/2005, S.P. wrote:
>I have a big data file with student records from various classes and
>schools. I am trying to create a file with only one record per class
>which will give me the teacher information for that class.
>The unique identifier for each teacher-classroom combination is
>constructed of the following two variables : idteach idlink
So, if I'm following you so far, you want one record for each
combination of IDTEACH and IDLINK found in your file:
>For example : I sometimes have for idteach = 28288, two groups of
>students, IDLINK = 2 and IDLINK = 3. I would need to keep only the
>first record with identical IDTEACH and IDLINK vars.
That is, again if I'm following you, want
. The first record where IDTECH=28288 and IDLINK=2
. The first record where IDTECH=28288 and IDLINK=3
So far, so good.
>I found this syntax on another web site and...I simply can't get it to
>work!! [It] works fine if the file does not contain different IDLINK
>[values] for one IDTEACH [value]:
>[From the other web site:]
>* To delete records with identical var1, var2 and var3.
>SORT CASES BY var1 var2 var3.
>ADD FILES FILE=* /BY var1 var2 var3 /FIRST=first.
>SELECT IF first.
>MY syntax [modified from the above]:
>SORT CASES BY IDTEACH IDLINK.
>ADD FILES FILE= 'C:\temp\datafile.sav' /*!!!!*/
> /BY IDTEACH IDLINK /FIRST=first.
>SELECT IF first.
The ADD FILES command is your problem. Your ADD FILES reads
'C:\temp\datafile.sav', replacing your working file. The sorting lost;
that was done in the work file.
If 'C:\temp\datafile.sav' is the file you want to work from, and it
isn't already sorted, you need it sorted as your working file:
GET FILE='C:\temp\datafile.sav'. /* 1. */
SORT CASES BY IDTEACH IDLINK.
ADD FILES FILE= * /* 2. */
/BY IDTEACH IDLINK /FIRST=first.
SELECT IF first.
1. Read 'C:\temp\datafile.sav' and sort it. Don't sort sort your
working file, throw away the sorting, and load 'C:\temp\datafile.sav'.
2. ADD FILES from the working file, which is sorted, rather than from
your disk file, which, it sounds like, is not.