data test;
input subject date date9.;
cards;
1 12DEC2011
2 11DEC2010
1 21OCT2012
3 20NOV2011
2 21DEC2012
;
proc sort data=test out=test1;
by subject descending date;
run;
data test2;
set test1;
by subject descending date;
if first.subject and first.date then flag='Y';
else flag='N';
run;
SQL:
data test;
input subject date date9.;
cards;
1 12DEC2011
2 11DEC2010
1 21OCT2012
3 20NOV2011
2 21DEC2012
;
proc sql;
create table test2 as
select subject,date,
case date
when max(date) then 'Y'
else 'N'
end as flag
from test
group by subject;
quit;
[quote="huazi":23ik7pc8]data test;
input subject date date9.;
cards;
1 12DEC2011
2 11DEC2010
1 21OCT2012
3 20NOV2011
2 21DEC2012
;
proc sort data=test out=test1;
by subject descending date;
run;
data test2;
set test1;
by subject descending date;
if first.subject and first.date then flag='Y';
else flag='N';
run;
SQL:
data test;
input subject date date9.;
cards;
1 12DEC2011
2 11DEC2010
1 21OCT2012
3 20NOV2011
2 21DEC2012
;
proc sql;
create table test2 as
select subject,date,
case date
when max(date) then 'Y'
else 'N'
end as flag
from test
group by subject;
quit;[/quote:23ik7pc8]
I like mischief.
[code:1suxqsgn]
data ahuige;
input
subject date date9.;
format date date9.;
cards;
1 12DEC2011
2 11DEC2010
1 21OCT2012
3 20NOV2011
2 21DEC2012
;run;
proc sql;
select *,byte((date=max(date))*11+78)
from ahuige
group by subject
order by subject,date
;quit;[/code:1suxqsgn]