DATA WORK.HAVE;
FORMAT Group $1. A 8. B 8. C 8. X 8.;
INFORMAT Group $1. A 8. B 8. C 8. X 8.;
INPUT Group A B C X;
INFILE DATALINES DLM='|' DSD;
DATALINES;
1|5|3|1|12
1|6|4|1|9
1|7|6|3|10
2|4|2|8|7
2|3|7|5|8
2|5|2|4|13
3|2|10|5|9
3|4|9|3|15
3|7|6|7|14
;
PROC SORT DATA=WORK.HAVE; BY GROUP X; RUN;
DATA WORK.WANT;
SET WORK.HAVE;
BY GROUP X;
IF LAST.GROUP AND LAST.X;
RUN;
By sorting the data by 'Group' and 'X', in the following datastep we can utilize the 'last.variable' feature. So the last iteration within each unique group id with the highest 'X' value within that unique group id.
Output:
Group A B C X
1 5 3 1 12
2 5 2 4 13
3 4 9 3 15