BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data test;

infile datalines;

input Rec $ RptDate date9. Sales Bonus ;

format rptdate date9.;

tot=sum(of sales,bonus);

return;

datalines;

225 1Jun2014 5 2

226 1Jul2014 2 2

227 1Aug2014 1 3

228 1Sep2014 4 2

229 1Oct2014 5 1

230 1Nov2014 6 2

;

run;

 

proc sort =test out=test2;

by Rec RptDate;

run;

 

proc expand =test2 out=test3;

id RptDate;

by Rec;

convert tot=tot_avg/ transformout=(movave 3 trimleft 2);

run;

 

My proc expand for some reason will not produce the 3 month tot_avg which is based on the sum of sales + bonus. I am attempting a 3 month moving average column

 

I get this instead

REC  RptDate tot_avg  Sales  Bonus    Tot
225 01JUN2014         5       2        7
226 01JUL2014         2       2        4
227 01AUG2014         1       3        4
228 01SEP2014         4       2        6
229 01OCT2014         5       1        6
230 01NOV2014         6       2        8

3 REPLIES 3
Reeza
Super User

You have a BY statement for the REC but each REC only has one record, so that doesn't make sense.

 

Your code is buggy, please ensure it runs when posting sample code.

SuryaKiran
Meteorite | Level 14

You don't need the "BY" and "ID".  Refer this document if you want to learn more http://support.sas.com/resources/papers/proceedings10/093-2010.pdf

Thanks,
Suryakiran
Rick_SAS
SAS Super FREQ

You need at least three observations in each BY group. For a discussion, examples, and links to other resources, see 

"Compute a moving average in SAS."

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 851 views
  • 2 likes
  • 4 in conversation