data test;
input id$ typeA$ typeB$ val
cards;
j1 a 1 1
j2 b 2 2
j3 b 4 6
j4 a 1 5
j5 b 2 4
j6 c 5 7
j7 a 4 8
j8 a 5 6
j9 b 3 7
j10 c 5 5
j11 c 5 6
;
run;
proc sql;
create table final1 as select * from,(sum(val)-val)/count(*)-1 as jr ,sum(val) as temp_sum,count(val) temp_count
from test group by typeA,typeB
create table final as
select id , typeA, typeB,val,(sum(val)-temp_sum)/(count(*)-temp_count) as ji,jr from final1
group by typeA;
quit;