BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hk2013
Fluorite | Level 6

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   15
13JAN2019  5  10   25
20JAN2019 5   10   35
27JAN2019  5  10   45

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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;
novinosrin
Tourmaline | Level 20
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;

SAS Innovate 2025: Call for Content

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!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 785 views
  • 3 likes
  • 3 in conversation