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.
data want; set have; retain sum_age 0; sum_age=sum(sum_age,age); run;
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;
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
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;
Change the MAX from this question to SUM. The idea is the same, you should be able to extend it to your new question:
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.