Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS: sum all values except one

Tags:

loops

sum

sas

I'm working in SAS and I'm trying to sum all observations, leaving out one each time. For example, if I have:

Count    Name      Grade
1        Sam        90
2        Adam       100
3        John       80
4        Max        60
5        Andrea     70

I want to output a value for Sam that is the sum of all grades but his own, and a value for Adam that is a sum of all grades but his own - etc.

Any ideas? Thanks!

like image 674
Deb Avatar asked Nov 26 '25 20:11

Deb


1 Answers

You can do it in a single proc sql instead, using key word calculated:

data have;
input Count    Name  $    Grade;
datalines;
1        Sam        90
2        Adam       100
3        John       80
4        Max        60
5        Andrea     70
;;;;
run;

proc sql;
    create table want as
    select *, sum(grade) as all_grades, calculated all_grades-grade as minus_grade
    from have;
quit;
like image 135
Reeza Avatar answered Nov 28 '25 13:11

Reeza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!