keeping rows with the latest date within that year for that firm

Reply
Frequent Contributor
Posts: 102

keeping rows with the latest date within that year for that firm

hi, i have:

cusipyeardatevar1var2want to end up with
1199019900101..
1199019900102..*
1199119910101..
11991199101021212
11991199112311212*
21990199001011515
21990199001021515*
21991199001011515
21991199001021717
21991199112011717
21991199112301919
21991199112311919*

i want to end up with the ones with the asterisk: the latest date observations for each year for each company. cud u plz help? thank you in advance

Trusted Advisor
Posts: 1,228

Re: keeping rows with the latest date within that year for that firm

proc sql;

create table want as

select * from have

group by cusip, year

having date=max(date);

quit;

Super Contributor
Posts: 490

Re: keeping rows with the latest date within that year for that firm

proc sort data=new;

by cusip year date;

run;

data want;

set new;

by cusip year date;

if last.year   then output;

run;

Ask a Question
Discussion stats
  • 2 replies
  • 1138 views
  • 0 likes
  • 3 in conversation