Here's an example that I think does what you want; inelegant, but it does the job.
I mocked up data. Only cases 1 and 5 should be chosen, if I understand correctly what you want. Assumes you have id variable of some kind that uniquely identifies cases.
data list free /id year (2F2).
begin data.
1 3 1 4 1 5 1 6 1 7 1 8
2 1 2 4 2 8
3 4 3 5 3 6 3 7 3 8
5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9
end data.
* Syntax to select only cases with years 3 4 5 6 7 and 8.
do if $casenum > 1.
if id ne lag(id) keep=1.
if id=lag(id) and year=lag(year)+1 keep=keep+1.
leave keep.
else.
compute keep=1.
end if.
execute.
aggregate outfile=* mode addvariables /break=id /min=min(keep) /max=max(keep).
select if max ge 6 and year ge 3 and year le 8.
execute.
delete variables min max keep.
** Look at the data and see if it did what you need.
------------------------------
Rick Marcantonio
Quality Assurance
IBM
------------------------------
Original Message:
Sent: Thu January 19, 2023 06:59 AM
From: Alma Victoria Taaje
Subject: Select Cases: If
Hi,
I am working on my thesis and have come across some issues when analysing my data. I have a variable with participants id number, but each participant has a number of years (coded 1 for year one, 2 for year 2 etc.). Some participants include years from 1 to 5, some from 1 to 10, and some might have year 1 and 3-7.
For my analysis I'd want to analyse each participant at year 3, 4, 5, 6, 7 and 8, but ONLY those participants who have reports from each of those years. When running Select Cases: if and entering the variable name >= 3 AND <=8, it also includes those cases who have reports from only year 4-8.
I have spent hours trying different commands and searching the internet for how to solve this. Does anyone have a solution for this?
------------------------------
Alma Victoria Taaje
------------------------------