im trying to sum the previous number
intial total number is Num_1 + num_2 and than after its Num_2+total
Have:
date num_1 Num_2
06JAN2019 5 10 13JAN2019 5 10 20JAN2019 5 10 27JAN2019 5 10
want
date num_1 Num_2 total
06JAN2019 5 10 1513JAN2019 5 10 2520JAN2019 5 10 3527JAN2019 5 10 45
Do like this
data have; input date:date9. num_1 Num_2; format date date9.; datalines; 06JAN2019 5 10 13JAN2019 5 10 20JAN2019 5 10 27JAN2019 5 10 ; data want; set have; if _N_=1 then total=sum(num_1, num_2); else total=total+num_2; retain total; run;
View solution in original post
data have; input date :date9. num_1 Num_2 ; format date date9.; cards; 06JAN2019 5 10 13JAN2019 5 10 20JAN2019 5 10 27JAN2019 5 10 ; data want; set have; if _n_=1 then total+sum(num_1 ,Num_2); else total+ Num_2; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Submit your idea!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.