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
TEMPORARYcommand beforeN OF CASES(seeTEMPORARY). - In some versions of
the program,
N OF CASEScan be specified only after a active dataset is defined.
Operations
-
N OF CASEStakes effect as soon as it is encountered in the command sequence. Thus, special attention should be paid to the position ofN OF CASESamong commands. See the topic Command Order for more information. -
N OF CASESlimits 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 theN OF CASEScommand. Any subsequentN OF CASEScommand that specifies a greater number of cases will be ignored. - If
N OF CASESspecifies more cases than can actually be built, the program builds as many cases as possible. - If
N OF CASESis used withSAMPLEorSELECT IF, the program reads as many records as required to build the specified n cases. It makes no difference whetherN OF CASESprecedes or followsSAMPLEorSELECT IF.
Example
GET FILE='/data/city.sav'.
N 100.
-
N OF CASESlimits 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 LISTdefines variables from file prsnnl.txt. -
N OF CASESlimits the active dataset to 25 cases after cases have been selected bySELECT IF. -
SELECT IFselects only cases in which SALARY is greater than $20,000. -
LISTproduces 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 CASEScommand is temporary. Only 25 cases are used in the firstFREQUENCIESprocedure. - The second
N OF CASEScommand 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).