How to limit cases by first ID

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

How to limit cases by first ID

Steven K. Erickson
Hi,

I'm trying to figure out how to select cases (limit) by the first ID
variable.  That is, I have a large database in which each subjects was
entered in multiple rows and can be identified by a patient ID variable. I
want to run a frequencies in which each subject will be counted ONCE only
for a particular variable.  I know that in SAS I would run:


data small;
set big;
by id;
if arrest=1;
if first.id then output;
run;

 How do I do this in SPSS?

Steve
Reply | Threaded
Open this post in threaded view
|

Re: How to limit cases by first ID

Richard Ristow
At 01:47 PM 10/31/2006, Steven K. Erickson wrote:

>I know that in SAS I would run:
>
>data small;
>set big;
>by id;
>if arrest=1;
>if first.id then output;
>run;

Sure. The following ADD FILES and SELECT IF constitute a direct
translation, except
. it reads from, and writes to, the current working dataset (working
file), rather than named datasets 'big' and 'small'
. it leaves variable FIRST_ID in the output file

Both the SAS and the SPSS code assume that
. The input file is sorted by ID
. Within ID, it's sorted so that selecting the first case found is
acceptable

This is tested; SPSS draft output. (To myself: code and listing not
kept separately. Data hand-entered in Data Editor; no raw data or input
code.)

* .................. .
LIST.
|-----------------------------|---------------------------|
|Output Created               |31-OCT-2006 14:26:38       |
|-----------------------------|---------------------------|
  ID Letter

   1 Alpha
   1 Beta
   1 Gamma
   2 Delta
   2 Epsilon
   3 Zeta
   3 Eta
   3 Theta
   3 Iota

Number of cases read:  9    Number of cases listed:  9


ADD FILES
    /FILE=*
    /BY ID
    /FIRST=FIRST_ID.
SELECT IF FIRST_ID.

LIST.
|-----------------------------|---------------------------|
|Output Created               |31-OCT-2006 14:26:38       |
|-----------------------------|---------------------------|
  ID Letter   FIRST_ID

   1 Alpha        1
   2 Delta        1
   3 Zeta         1

Number of cases read:  3    Number of cases listed:  3