SAS_Complicated Cumulative Sum_Transpose

Accepted Solution Solved
Reply
Contributor
Posts: 34
Accepted Solution

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)

 

Thanks in advance for your helps.


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

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

tab_report.png

View solution in original post


All Replies
Trusted Advisor
Posts: 1,789

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.

Contributor
Posts: 34

Re: SAS_Complicated Cumulative Sum_Transpose

Could you please write the code?
Super User
Super User
Posts: 7,720

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: 8,820

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

tab_report.png

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 144 views
  • 1 like
  • 4 in conversation