Learning SAS? Welcome to the exclusive online community for all SAS learners.

how to find the row totals .

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

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,044

Re: how to find the row totals .

Posted in reply to tlnarayana26
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

View solution in original post


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

Re: how to find the row totals .

Posted in reply to tlnarayana26
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

Trusted Advisor
Posts: 1,137

Re: how to find the row totals .

Posted in reply to tlnarayana26

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.

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

Discussion stats
  • 2 replies
  • 283 views
  • 0 likes
  • 3 in conversation