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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1281 views
  • 0 likes
  • 2 in conversation