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

Dear, I hope you are very well, my question is the following: I have 3 columns with numerical variables and I must accumulate them from the oldest to the newest as I show in the following table of how the data is and how the final table should be.

DATECATEG_ACATEG_BCATEG_C
16-01-2022150
15-01-2022813
14-01-2022401
13-01-2022110
12-01-2022100

 


Results.

DATECATEG_ACUM_ACATEG_BCUM_BCATEG_CCUM_C
16-01-20221155704
15-01-20228141234
14-01-2022460111
13-01-2022121100
12-01-2022110000

 

 

thanks for your time

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

If you have PROC EXPAND, this will do cumulative sums as follows:

 

proc sort data=have;
    by date;
run;
proc expand data=have out=want;
    convert categ_a=cum_a categ_b=cum_b categ_c=cum_c/transformout=(cusum);
run;

Otherwise you would have to do this in a DATA step.

 

proc sort data=have;
    by date;
run;
data want;
    set have;
    cum_a+categ_a;
    cum_b+categ_b;
    cum_c+categ_c;
run;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Please explain how in the original data CATEG_C is always zero but in the output CUM_C is sometimes not zero. And lots of other discrepancies between the input and output also exist and require explanation. Thanks.

--
Paige Miller
Andres_Fuentes1
Calcite | Level 5
sorry, I changed the table for a smaller one for the example, I will renew it.
PaigeMiller
Diamond | Level 26

If you have PROC EXPAND, this will do cumulative sums as follows:

 

proc sort data=have;
    by date;
run;
proc expand data=have out=want;
    convert categ_a=cum_a categ_b=cum_b categ_c=cum_c/transformout=(cusum);
run;

Otherwise you would have to do this in a DATA step.

 

proc sort data=have;
    by date;
run;
data want;
    set have;
    cum_a+categ_a;
    cum_b+categ_b;
    cum_c+categ_c;
run;
--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2257 views
  • 0 likes
  • 2 in conversation