How to Sum by Rows

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

How to Sum by Rows

Hello All,

May I know how can I sum values by rows? For example, I want to sum out the output value by plant.

BuildingBuilding NumberUnitLineOutput
KLM11c line29947
KLM12c line24036
KLM21c line37728
KLM22c line31036
KLM31c line34986
KLM32c line35502
KLM41c line36332
KLM42c line36456
KLM51c line36516
KLM52c line34918
KLM61c line36298
KLM62c line36840

Accepted Solutions
Solution
‎08-21-2015 07:49 AM
Valued Guide
Posts: 854

Re: How to Sum by Rows

Have you run my code?  That's what it's doing.

View solution in original post


All Replies
Esteemed Advisor
Posts: 5,198

Re: How to Sum by Rows

What is plant?

What do you mean by "sum by rows". Attach desired output.

Without knowing, it sounds like a real basic report/calculation. What kind of SAS training have taken?

Data never sleeps
New Contributor
Posts: 4

Re: How to Sum by Rows

Sorry, it should be by "Building Number".

Solution
‎08-21-2015 07:49 AM
Valued Guide
Posts: 854

Re: How to Sum by Rows

Have you run my code?  That's what it's doing.

Valued Guide
Posts: 854

Re: How to Sum by Rows

Without an explanation of what 'plant' is or what  your desired output is this is what I came up with:

data have;

infile cards dsd;

input Building$    Building_Number    Unit    Line$    Output;

cards;

KLM,1,1,c line,29947

KLM,1,2,c line,24036

KLM,2,1,c line,37728

KLM,2,2,c line,31036

KLM,3,1,c line,34986

KLM,3,2,c line,35502

KLM,4,1,c line,36332

KLM,4,2,c line,36456

KLM,5,1,c line,36516

KLM,5,2,c line,34918

KLM,6,1,c line,36298

KLM,6,2,c line,36840

;

proc sql;

create table want as

select *,sum(output) as sum

from have

group by building,building_number;

Grand Advisor
Posts: 17,411

Re: How to Sum by Rows

There are many many ways. Here's a proc means version

proc means data=have NWAY;

CLASS building buildingNumber;

var output;

output out=want sum=;

run;

New Contributor
Posts: 4

Re: How to Sum by Rows

ues mark johson..it works..thank u so  much !

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 394 views
  • 0 likes
  • 4 in conversation