BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Khaladdin
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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
Khaladdin
Quartz | Level 8
Could you please write the code?
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Cynthia_sas
SAS Super FREQ

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1121 views
  • 1 like
  • 4 in conversation