In reply to David.

I'll assume that there's a patno for patient number, sort the data 1st by using patientno.

Data output;
Set input;
By patno;
If First.patno;
diagnosis +1;
If Last.patno;
If diagnosis >3;
Run;