BookmarkSubscribeRSS Feed
xyxu
Quartz | Level 8

Let's say N=8 and M= 6. If the number of non-missing values within a rolling window is fewer than 6, the program should set the output value to be missing. Not sure if the following does this:

proc expand data = have out = want method = none;
	by firm;
	id date;
	convert x = y/ transformout = (movsum 8 trimleft 5);
run;
4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

I'm not entirely sure here, but I don't think Proc Expand has such an option. 

 

Do you want an alternative to Proc Expand?

xyxu
Quartz | Level 8
Thanks for confirming that proc expand cannot do this. There are definitely (less elegant) solutions.
Ksharp
Super User
/*Assuming there is no gap between dates*/
data have;
call streaminit(123);
do firm='A' ,'B' ,'C';
  do date='01jan2010'd to '20dec2021'd;
   x=rand('uniform');output;
  end;
end;
format date date9.;
run;


%let n=8;
%let m=6;
data want;
   set have;
   by firm;
 array t{0:%eval(&n.-1)} _temporary_;
if first.firm then do; n=0; call missing(of t{*});end;
n+1;
t{mod(n,&n.)}=x;
if n ge &n. and n(of t{*}) ge &m. then moving_mean=mean(of t{*});
drop n;
run;

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!
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
  • 4 replies
  • 475 views
  • 2 likes
  • 3 in conversation