1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
* http://www.spss.com/tech/stat/kw/Kw67/tech67.htm

*QUESTION: I have a variable in my file which represents different groups. I want to randomly 
select a specific number of cases from each group. How can I do this? 

* ANSWER: Assume the grouping variable is called "group" for the purpose of this exercise. The 
syntax below will select two cases from each group. 

COMPUTE tempvar=UNIFORM(10).
SORT CASES BY group tempvar (A).
SPLIT FILE BY group.
COMPUTE tempvar=1.
CREATE filter=CSUM(tempvar).
RECODE filter (1 thru 2=1) (3 thru highest=0).
FILTER BY filter.
EXECUTE