You want to detect and delete all; cases (within a patientid) with unchanging var1, but changing stage:
data have;
input PatientID Stage Var1;
seq+1;
datalines;
1001 1 0
1001 2 0
1001 2 1
1002 2 1
1005 3 3
1006 2 1
1010 3 0
1010 3 2
;
data want;
set have;
by patientid var1 stage notsorted;
if ???? then delete;
run;
Using the by pateindid var1 stage notsorted; has patientid as the major grouping key, stage as the minor key, and var1 as the middle key. SAS honors this hierarchy, such that when a given key changes (setting its first. indicator, it also sets the indicators for all keys to its right). BTW, notsorted means that, for a given patientid/var1 the stage values can go up or down - SAS need not expect either ascending or descending order in identifying groups, for any of the "by" keys.
This means that if you encounter a record that starts a new stage value (first.stage=1), but does not at the same time start a new var1 value, then it should be deleted. Similarly if it ends the current value of stage (last.stage=1) but does not end the current value of var1, then it should also be deleted. Build the expression to test for those conditions, and put it in as a replacement for the ???? above.
... View more