Solved
Contributor
Posts: 44

# how to find the row totals .

hi friends

i have the problem finding the row totals.

i have the x  data set like this

data x;

infile datalines;

input x_jan x_feb x_mar y_jan y_feb;

datalines;

10 25 12 14 17

25 36 12 14 45

13 15 17 10 12

run;

finding totals for x  and y

i want like this

x_jan  x_feb  x_mar  y_jan  y_feb     x_total       y_total

10      25       12        14     17           47             31

25      36       12        14      45          73             59

13      15       17        10      12          45             22

here finding x_total and y_total  respectively x months and y months .

using macros

plz  help me .

thank you

Lakshmi narayana.T

Accepted Solutions
Solution
‎04-18-2015 09:42 AM
Super User
Posts: 10,766

## Re: how to find the row totals .

```data x;
infile datalines;
input x_jan x_feb x_mar y_jan y_feb;
x_total=sum(of x_:);  y_total=sum(of y_:) ;
datalines;
10 25 12 14 17
25 36 12 14 45
13 15 17 10 12
run;

```

Xia Keshan

All Replies
Solution
‎04-18-2015 09:42 AM
Super User
Posts: 10,766

## Re: how to find the row totals .

```data x;
infile datalines;
input x_jan x_feb x_mar y_jan y_feb;
x_total=sum(of x_:);  y_total=sum(of y_:) ;
datalines;
10 25 12 14 17
25 36 12 14 45
13 15 17 10 12
run;

```

Xia Keshan

Posts: 1,147

## Re: how to find the row totals .

alternatively by arrays

data x;

infile datalines;

input x_jan x_feb x_mar y_jan y_feb;

datalines;

10 25 12 14 17

25 36 12 14 45

13 15 17 10 12

;

run;

data want;

set x;

array y(*) y_:;

array x(*) x_:;

y_total=sum(of y(*));

x_total=sum(of x(*));

run;

Thanks,

Jag

Thanks,
Jag
🔒 This topic is solved and locked.