Assuming I understand what you mean:
data test;
input P_Level$ PL1$ PL2$ PL3$ QTY1 QTY2 STATUS$;
cards;
P1 A . . 3 4 N
P2 A PL11 . 10 20 N
P3 A PL11 PL21 1 2 N
P3 A PL11 PL22 3 4 Y
P3 A PL11 PL23 1 3 N
P2 A PL12 . 30 40 N
P3 A PL12 PL21 1 3 N
P3 A PL12 PL22 3 3 Y
P3 A PL12 PL23 1 5 N
P2 A PL13 . 33 43 N
P3 A PL13 PL21 1 6 N
P3 A PL13 PL22 3 6 Y
P3 A PL13 PL23 1 6 N
;
run;
data test;
set test;
if p_level in ('P1' 'P2') then group+1;
run;
proc sql;
create table want as
select *,case
when(p_level='P1') then
(select sum(sum(qty1,qty2)) from test where status='Y')
when(p_level='P2') then
(select sum(sum(qty1,qty2)) from test where group=a.group and status='Y')
else . end as sum
from test as a;
quit;
... View more