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

## How do I sum values from prevs value

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

## Re: How do I sum values from prevs value

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;``````
2 REPLIES 2
Tourmaline | Level 20

## Re: How do I sum values from prevs value

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

## Re: How do I sum values from prevs value

``````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;
``````
Discussion stats
• 2 replies
• 695 views
• 3 likes
• 3 in conversation