DATA Step, Macro, Functions and more

Finding last observation

Reply
Frequent Contributor
Frequent Contributor
Posts: 103

Finding last observation

Have:   
ID v1v2v3
1-3aa
1-2bb
1-1cb
11db
2-20aa
2-6bb
2-3cb
2-2db
31aa
    
want:   
ID v1v2v3
11db
2-2db
31aa

 

I am trying to find one unique observation per id.   v1 ranges from 1 to -20. I am trying  to output  the highest and unique value possible for v1. 

Super User
Posts: 7,832

Re: Finding last observation

Very easy.

proc sort data=have;
by id v1;
run;

data want;
set have;
by id;
if last.id;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,433

Re: Finding last observation

Is the ID and v1 combination unique?

If so, use SQL with group by ID having max(v1) = v1.

Data never sleeps
Ask a Question
Discussion stats
  • 2 replies
  • 259 views
  • 1 like
  • 3 in conversation