proc sql;
create table t1 (id int, typ int, dt char(8), qty int);
insert into t1
values (1, 2, '20190325', 50)
values (2, 2, '20190320', 15)
values (3, 3, '20190401', 50)
values (4, 3, '20190405', 5)
values (5, 1, '20190406', 25)
values (6, 2, '20190411', 5)
values (7, 3, '20190412', 15);
create table t2 as select id, a.typ, input(dt,yymmdd8.) as date format=date9.,dt, qty
from t1(where=(input(dt,yymmdd8.) < '10Apr2019'd )) a
inner join (
select typ, max(input(dt,yymmdd8.)) as MaxDate
from t1(where=(input(dt,yymmdd8.) < '10Apr2019'd))
group by typ
) b on input(a.dt,yymmdd8.)=b.MaxDate;
quit;
... View more