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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 695 views
  • 3 likes
  • 3 in conversation