# SPSS Recoding Question

##### New Member
Thank you for entertaining my question, which I hope is a Recoding question, but since I’ve reached a point of confusion, perhaps it is not.

I have tried a several textbooks, this and other forums, YouTube and some trial and error.

I inherited a data set of ~16,000 people who had medical exams over a 4 year period on a continuous annual enrollment plan.

Specifically, new patients could enroll each year and, if they enrolled in year one, would have one year of follow-up on year 2.

Likewise, if they enrolled in year 2 they would have one year of follow up on year 3
If enrolled in year 3, the would have a year of follow-up on year 4

Similarly, the could have 2 years of follow up if they enrolled in year 1 and subsequent exams in year 2 and year 3 or enrolled in year 2 with subsequent exams in year 3 and year 4.

Finally, they could have 3 years of follow-up if they enrolled in year 1 and had follow-up visits in years 2, 3 and 4.

Column 1/Var0001 = ID
Column 2/Var0002 = Exam Year defined as 1, 2, 3, or 4.

if (Exam.Year=1 & Exam.Year=2) Follow.Up=1.
if (Exam.Year=2 & Exam.Year=3) Follow.Up=1.
if (Exam.Year=3 & Exam.Year=4) Follow.Up=1.
if (Exam.Year=1 & Exam.Year=2 & Exam.Year=3) Follow.Up=2.
if (Exam.Year=2 & Exam.Year=3 & Exam.Year=4) Follow.Up=2.
if (Exam.Year=1 & Exam.Year=2 & Exam.Year=3 & Exam.Year=4) Follow.Up=3.
recode Follow.up (SYSMIS=0).

Where:

1 = 1 Year Follow-up
2 = 2 Year Follow-up
3 = 3 Year Follow-up

If I run this syntax all I get are zero’s so am now at a loss. My syntax ability is “ok” but far from fluent.

Many thanks in advance for any suggestions.

#### helicon

##### Member
You should provide a minimal dataset and your expected output. At the very least your code doesn't work because it's currently set up so no case can logically be true (i.e. a variable can't possibly have two simultaneous values). If the exam years are contained in the same variable, it'll need to be parsed into separate variables first.

##### New Member
I'll look into doing just that. Many thanks for your kind response.

#### helicon

##### Member
Presumably your data is in long format and looks something like this:

Code:
id     exam.year
1	1
1	2
1	3
1	4
2	2
2	3
3	4
4	1
4	2
4	3
5	3
5	4
6	4
In which case you could use aggregate the max and min exam year by id and then subtract one value from the other.

Code:
aggregate /break = id / exam.year_max = max(exam.year) / exam.year_min = min(exam.year).
compute follow.up = exam.year_max - exam.year_min.
exe.
This assumes there are no missing follow ups though.

You might also want to restructure your data to wide format:

Code:
sort cases by id.
casestovars /id = id / groupby = index.
Which will result in this:

Code:
  id follow.up exam.year.1 exam.year.2 exam.year.3 exam.year.4
1         3           1           2           3           4
2         1           2           3
3         0           4
4         2           1           2           3
5         1           3           4
6         0           4

#### dungdn93

##### New Member
At least your code does not work because it is set up so there is no case can reasonably be true ie a variation can not have two values simultaneously