SAS datastep/SQL select latest record from multiple records with same ID

Luke Henz picture Luke Henz · Jun 3, 2013 · Viewed 12.9k times · Source

For example I have a dataset as below:

id Date
1  2000/01/01
1  2001/01/01
1  2002/01/01
2  2003/01/01

By datastep or sql, how could I get the record with id = 1 and latest Date 2002/01/01? Help is appreciated and thanks in advance.

Answer

Ankur Trapasiya picture Ankur Trapasiya · Jun 3, 2013

Try this sql.

select id,max(Date)
from yourtable
group by id;