FIRST and LAST Subcommands (MATCH FILES command)
FIRST
and LAST
create logical variables that flag
the first or last case of a group of cases with the same value for
the BY
variables.
-
FIRST
andLAST
must follow allTABLE
andFILE
subcommands and any associatedRENAME
andIN
subcommands. -
FIRST
andLAST
have only one specification—the name of the flag variable. -
FIRST
creates a variable with the value 1 for the first case of each group and the value 0 for all other cases. -
LAST
creates a variable with the value 1 for the last case of each group and the value 0 for all other cases. - Variables created by
FIRST
andLAST
are automatically attached to the end of the resulting file and cannot be dropped. - If one file has several cases with the same values
for the key variables,
FIRST
orLAST
can be used to create a variable that flags the first or last case of the group.
Example
MATCH FILES TABLE='/data/house.sav'
/FILE='/data/persons.sav'
/BY=HOUSEID /FIRST=HEAD.
- The variable HEAD contains the value 1 for the first person in each household and the value 0 for all other persons. Assuming that the persons.sav file is sorted with the head of household as the first case for each household, the variable HEAD identifies the case for the head of household.
Example
* Using match files with only one file.
* This example flags the first of several cases with
the same value for a key variable.
MATCH FILES FILE='/data/persons.sav'
/BY HOUSEID /FIRST=HEAD.
SELECT IF (HEAD EQ 1).
CROSSTABS JOBCAT BY SEX.
-
MATCH FILES
is used instead ofGET
to read the data file persons.sav. TheBY
subcommand identifies the key variable (HOUSEID), andFIRST
creates the variable HEAD with the value 1 for the first case in each household and the value 0 for all other cases. -
SELECT IF
selects only the cases with the value 1 for HEAD, and theCROSSTABS
procedure is run on these cases.