Solved
Contributor
Posts: 64

# SAS_Complicated Cumulative Sum_Transpose

Hi,

I want to ask a question about cumulative sum. I think I can explain better by using the simple sample. So, I have the following dataset:

Group       Time                Value

A               14:25                5

A               14:25                10

A               14:26                 8

B               14:25                 4

B               14:25                 7

C               14:25                12

C               14:25                 3

C               14:26                 6

C               14:26                 9

I want to get the following datasets:

Time         A                  B                    C

14:25       15 (5+10)     11 (4+7)          15(12+3)

14:26        8                  0                     15(6+9)

Accepted Solutions
Solution
‎06-29-2017 08:34 AM
SAS Super FREQ
Posts: 9,434

## Re: SAS_Complicated Cumulative Sum_Transpose

Hi:

As a comparison, either PROC REPORT or PROC TABULATE could produce a report with only 1 pass through the data.

cynthia

All Replies
Posts: 3,288

## Re: SAS_Complicated Cumulative Sum_Transpose

PROC SUMMARY to get the sums you want.

PROC REPORT or PROC TRANSPOSE to get the table you want from the sums calculated above.

--
Paige Miller
Contributor
Posts: 64

## Re: SAS_Complicated Cumulative Sum_Transpose

Could you please write the code?
Super User
Posts: 9,855

## Re: SAS_Complicated Cumulative Sum_Transpose

This is just a guess as not typing in that data nor, guessing he strcuture - post test data in the form of a datastep!

```proc sq;
create table INTER as
select TIME,
GROUP,
sum(VALUE) as VALUE
from    HAVE:
group by TIME,
GROUP;
quit;
proc transpose data=inter out=want;
by time;
var value;
id group;
run;```
Solution
‎06-29-2017 08:34 AM
SAS Super FREQ
Posts: 9,434

## Re: SAS_Complicated Cumulative Sum_Transpose

Hi:

As a comparison, either PROC REPORT or PROC TABULATE could produce a report with only 1 pass through the data.

cynthia

☑ This topic is solved.