Overview (N OF CASES command)

N OF CASES (alias N) limits the number of cases in the active dataset to the first n cases.

Basic Specification

The basic specification is N OF CASES followed by at least one space and a positive integer. Cases in the active dataset are limited to the specified number.

Syntax Rules

  • To limit the number of cases for the next procedure only, use the TEMPORARY command before N OF CASES (see TEMPORARY).
  • In some versions of the program, N OF CASES can be specified only after a active dataset is defined.

Operations

  • N OF CASES takes effect as soon as it is encountered in the command sequence. Thus, special attention should be paid to the position of N OF CASES among commands. See the topic Command Order for more information.
  • N OF CASES limits the number of cases that are analyzed by all subsequent procedures in the session. The active dataset will have no more than n cases after the first data pass following the N OF CASES command. Any subsequent N OF CASES command that specifies a greater number of cases will be ignored.
  • If N OF CASES specifies more cases than can actually be built, the program builds as many cases as possible.
  • If N OF CASES is used with SAMPLE or SELECT IF, the program reads as many records as required to build the specified n cases. It makes no difference whetherN OF CASES precedes or follows SAMPLE or SELECT IF.

Example

GET FILE='/data/city.sav'.
N 100.
  • N OF CASES limits the number of cases on the active dataset to the first 100 cases. Cases are limited for all subsequent analyses.

Example

DATA LIST FILE='/data/prsnnl.txt' 
  / NAME 1-20 (A) AGE 22-23 SALARY 25-30.
N 25.
SELECT IF (SALARY GT 20000).
LIST.
  • DATA LIST defines variables from file prsnnl.txt.
  • N OF CASES limits the active dataset to 25 cases after cases have been selected by SELECT IF.
  • SELECT IF selects only cases in which SALARY is greater than $20,000.
  • LIST produces a listing of the cases in the active dataset. If the original active dataset has fewer than 25 cases in which SALARY is greater than 20,000, fewer than 25 cases will be listed.

Example

DATA LIST FILE='/data/prsnnl.txt' 
  / NAME 1-20 (A) AGE 22-23 SALARY 25-30 DEPT 32.
LIST.
TEMPORARY.
N 25.
FREQUENCIES VAR=SALARY.
N 50.
FREQUENCIES VAR=AGE.
REPORT FORMAT=AUTO /VARS=NAME AGE SALARY /BREAK=DEPT 
  /SUMMARY=MEAN.
  • The first N OF CASES command is temporary. Only 25 cases are used in the first FREQUENCIES procedure.
  • The second N OF CASES command is permanent. The second frequency table and the report are based on 50 cases from file prsnnl.txt. The active dataset now contains 50 cases (assuming that the original active dataset had at least that many cases).