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;

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 869 views
  • 2 likes
  • 3 in conversation