Well, in that case, provided you with the correct answer. It can be written more conventionally as : PROC SQL; CREATE TABLE RES AS SELECT DISTINCT CUSTOMERNUM, PATIENTID, GROUPEND FROM HELLO GROUP BY CUSTOMERNUM, PATIENTID HAVING GROUPEND = MAX(GROUPEND); QUIT; You don't need the DISTINCT option if the groupend dates are unique for each value of patientid and customernum. PG
... View more