The SAS Output Delivery System and reporting techniques

How to create a running total

Reply
N/A
Posts: 0

How to create a running total

input data looks like this
id date counts
10 5/1 10
10 5/2 5
10 5/3 10

data runningtot;
set input end = finished;
totcount + count;
output;
if finished then do;
date = . ;
count = .;
output;
end;
run;
output will look like this:
ID DATE COUNT TOTCOUNT
10 5/1 10 10
10 5/2 5 15
10 5/3 10 25
10 25
SAS Super FREQ
Posts: 8,868

Re: How to create a running total

Posted in reply to deleted_user
Actually, the data will look like this:
[pre]
Obs id date count totcount
1 10 05/01 10 10
2 10 05/02 5 15
3 10 05/03 10 25
4 10 . . 25
[/pre]
(Note missing values for OBS #4 for the Date var and the COUNT var) -- if you do a proc print on the runningtot table based on the following code:
[pre]
data input;
infile datalines;
input id date : mmddyy8. count;
return;
datalines;
10 5/1/07 10
10 5/2/07 5
10 5/3/07 10
;
run;

data runningtot;
set input end = finished;
totcount + count;
output;
if finished then do;
date = . ;
count = .;
output;
end;
run;

proc print data=runningtot;
format date mmddyy5.;
run;
[/pre]

Not sure what your question was.
cynthia
Ask a Question
Discussion stats
  • 1 reply
  • 177 views
  • 0 likes
  • 2 in conversation