Try this:
DATASET CLOSE ALL.
NEW FILE.
DATA LIST FREE /id tooth.
BEGIN DATA.
1 1
2 1
2 2
3 1
4 1
5 1
5 2
6 1
6 2
7 1
8 1
9 1
9 2
10 1
END DATA.
* Obviously, made up data. You start here and change to your own variable name for id.
AGGREGATE /OUTFILE=* MODE ADDVARIABLES /BREAK=ID /NT=N.
* Write out two temp files to a writeable location.
FILE HANDLE Temp1 /NAME="/Users/rick/tmp/t1.sav".
FILE HANDLE Temp2 /NAME="/Users/rick/tmp/t2.sav".
DATASET NAME Original.
TEMPORARY.
SELECT IF NT=1.
SAVE OUT Temp1.
TEMPORARY.
SELECT IF NT=2.
SAVE OUT Temp2.
SET SEED=5456432.
GET FILE Temp2.
COMPUTE random=UNIFORM(1).
SORT CASES BY id random.
COMPUTE keep=MOD($CASENUM,2).
EXECUTE.
SELECT IF keep.
SAVE OUT Temp2.
MATCH FILES FILE=Temp1 /FILE=Temp2 /DROP random keep /BY id.
SAVE OUT Temp1.
ERASE FILE Temp2.
I think that will do it. Sorry to take so long. Got a little busy for awhile. :)
Temp1 file has your data, one per id, randomly chosen. Change the SET SEED value if you want.
------------------------------
Rick Marcantonio
Quality Assurance
IBM
------------------------------
Original Message:
Sent: Thu November 04, 2021 04:00 PM
From: Jakob Sjögren
Subject: How to randomize one case per patient?
Dear all,
I have a small data set consisting of 114 root filled teeth, 57 cases (painful root filled teeth) and 57 controls (non-painful root filled teeth). Ten research subjects contribute with two painful teeth each. Now I want to randomize so every research subject only contribute with one tooth each.
How do I do that in SPSS? I work with version 25.
Best wishes,
------------------------------
Jakob Sjögren
------------------------------
#SPSSStatistics