BookmarkSubscribeRSS Feed
franph
Calcite | Level 5

Hi, not sure if my previous post uploaded, sorry if you see it 2x ..... I have reworded a bit too

1. I want to sum amounts by trandate and show in new column called dailybal

2. then in a new column called accruingbal show a running balance using values in dailybal ... only if there is a value in dailybal

data example

trandate          amount

01/01/2015     5

04/01/2015     2

04/01/2015     7

06/01/2015     9

07/01/2015     3

07/01/2015     4

09/01/2015     6

desired result

trandate          amount     dailybal     accruingbal

01/01/2015     5               5               5

04/01/2015     2         

04/01/2015     7               9               14

06/01/2015     9               9               23

07/01/2015     3         

07/01/2015     4               7               30

09/01/2015     6               6               6

thanks for your help 🙂

3 REPLIES 3
AskoLötjönen
Quartz | Level 8

data example;

attrib trandate informat=ddmmyy10. format=ddmmyy10.;

infile cards dlm=' ';

input trandate amount 16;

cards;

01/01/2015     5

04/01/2015     2

04/01/2015     7

06/01/2015     9

07/01/2015     3

07/01/2015     4

09/01/2015     6

;

run;

data want;

retain trandate amount dailybal accruingbal;

set example;

by trandate;

if first.trandate then dailybal=0;

dailybal+amount;

accruingbal+amount;

run;

data want;

  set want;

by trandate;

if first.trandate and not last.trandate then do;

  dailybal=.;

  accruingbal=.;

end;

run;

Ksharp
Super User

Code: Program

data have;
input trandate   : mmddyy10.   amount;
format trandate   mmddyy10.  ;
cards;
01/01/2015 5
04/01/2015 2
04/01/2015 7
06/01/2015 9
07/01/2015 3
07/01/2015 4
09/01/2015 6
;
run;
proc summary data=have;
by trandate;
var amount;
output out=temp(drop=_:) sum=;
run;
data want;
set temp;
cumsum+amount;
run;
franph
Calcite | Level 5

thanks for both your suggestions, helped alot

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1291 views
  • 0 likes
  • 3 in conversation