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

Hi,

I'm trying to use proc expand to do a rolling sum based on multiple columns. I'm able to do a rolling sum if I'm just using my year_month date column, but when I add another dimension, I can't have it perform the sum taking into account the 2nd dimension. I have the first three columns below.  I'm not sure how to get the 4th column.  I can do it if I I'm not including the 'State' field, but I need it broken out by month and state.

Thank you in advance!

Tom

Year_MonthStateValueRolling3
201401CA11
201402CA12
201403CA1134
201404CA1235
201405CA1437
201401TX12
201402TX14
201403TX1036
201404TX1135
201405TX1637
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Not sure I understand what the problem is. Anyway, this gets the expected result:

data have;

input Year_Month State $ Value;

datalines;

201401 CA 11

201402 CA 12

201403 CA 11 34

201404 CA 12 35

201405 CA 14 37

201401 TX 12

201402 TX 14

201403 TX 10 36

201404 TX 11 35

201405 TX 16 37

;

proc expand data=have out=want;

by state;

id  year_month;

convert Value=Rolling3 / transformout=(movsum 3 trimleft 2);

run;

PG

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

Not sure I understand what the problem is. Anyway, this gets the expected result:

data have;

input Year_Month State $ Value;

datalines;

201401 CA 11

201402 CA 12

201403 CA 11 34

201404 CA 12 35

201405 CA 14 37

201401 TX 12

201402 TX 14

201403 TX 10 36

201404 TX 11 35

201405 TX 16 37

;

proc expand data=have out=want;

by state;

id  year_month;

convert Value=Rolling3 / transformout=(movsum 3 trimleft 2);

run;

PG

PG
teg_76
Calcite | Level 5

Thank you PG!!!!!!!!!!!!!  That was the logic I needed to apply.  You just saved me a lot of time Smiley Happy

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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