BookmarkSubscribeRSS Feed
ajay_mishra
Calcite | Level 5

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.

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26
data want;
  set have;
  retain sum_age 0;
  sum_age=sum(sum_age,age);
run;
novinosrin
Tourmaline | Level 20

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;
art297
Opal | Level 21

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

 

novinosrin
Tourmaline | Level 20

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;
Reeza
Super User

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

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1389 views
  • 2 likes
  • 5 in conversation