Home > database >  Adding two rows in SAS
Adding two rows in SAS

Time:10-14

Picture

I have a table called A and I want to create a new table that has the same values but at the end of the table, another row called "total", that does the following computation:

(A BB ES)-(BD L S).

Essentially, I want the same table as I have in the attached screenshot, but with an added row called Total that has the value of "32" which came from (A BB ES)-(BD L S).

so far my code is the following:

proc sql;
create table A as select 'Total' as Name from A
union
select * from A;
quit

What I want

CodePudding user response:

Does the following meet expectations?

select name, count
from A
union all
select 'Total', 
  Sum(case when name in ('a','bb','es') then count end)
  -Sum(case when name in ('bd','l','s') then count end)
from A
  • Related