Anne
Anne

Reputation: 11

Create variable counting unique IDs in long format table

I would like to structure my long format SPSS file so I can clean it and get a better overview. However, I run into some problems.

Patients appear several times in the database (Column patientID). How can I make a new variable that contains only 1 patient ID preferable on the line with baseline data/first moment that questionnaires are completed?

enter image description here

I have consulted with my colleagues, but without concrete solutions/answers

Upvotes: 1

Views: 191

Answers (1)

eli-k
eli-k

Reputation: 11360

This can be done using the lag function - after sorting the file:

sort cases by PatientID_Pseudo OpenInvulMomenten.
if $casenum=1 or ($casenum>1 and PatientID_Pseudo<>lag(PatientID_Pseudo)) newvar=PatientID_Pseudo.
exe.

Upvotes: 0

Related Questions