Solved
New Contributor
Posts: 4

# 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.

 Building Building Number Unit Line Output 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

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

## Re: How to Sum by Rows

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

All Replies
Super User
Posts: 5,884

## 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: 864

## Re: How to Sum by Rows

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

Valued Guide
Posts: 864

## 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;

Super User
Posts: 23,763

## 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 and locked.

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