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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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