How to sum a particular column in SAS through data step.

Reply
Occasional Contributor
Posts: 6

How to sum a particular column in SAS through data step.

How to sum a particular column in SAS.

If I have a data then 

age

15

23

63

56

78

45

How can I get the sum of the variable Age in Data Step.

Super User
Super User
Posts: 9,441

Re: How to sum a particular column in SAS through data step.

Posted in reply to ajay_mishra
data want;
  set have;
  retain sum_age 0;
  sum_age=sum(sum_age,age);
run;
PROC Star
Posts: 1,595

Re: How to sum a particular column in SAS through data step.

Posted in reply to ajay_mishra

I prefer a sum statement

data have;
input age;
datalines;
15
23
63
56
78
45
;

data want;
set have;
sum_of_age+age;
run;
PROC Star
Posts: 8,149

Re: How to sum a particular column in SAS through data step.

Posted in reply to ajay_mishra

The two methods proposed will result in the running sums for each record, with only the last record reflecting the total sum. Is that what you want?

 

Art, CEO, AnalystFinder.com

 

PROC Star
Posts: 1,595

Re: How to sum a particular column in SAS through data step.

Posted in reply to ajay_mishra

Hmm  love Art's attention to finer detail:

 

data have;
input age;
datalines;
15
23
63
56
78
45
;

data want;
set have end=last;
sum_of_age+age;
if last;
run;
Super User
Posts: 23,337

Re: How to sum a particular column in SAS through data step.

Posted in reply to ajay_mishra

Change the MAX from this question to SUM. The idea is the same, you should be able to extend it to your new question:

 

 

https://communities.sas.com/t5/General-SAS-Programming/How-to-find-the-maximum-value-in-a-variable-t...

 

Ask a Question
Discussion stats
  • 5 replies
  • 127 views
  • 2 likes
  • 5 in conversation