I would like to compute the rolling standard deviation (STDX) for different IDs of the variable X using 3 observations (with no less than 2). For example, in row 5 after two observations of X (0.2 and 0.1), I want to compute STDX as 0.05. In row 6, after three observations of X (0.2, 0.1 and 0.3), I wnat to compute STDX as 0.082
input id date X STDX;
1 194503 . .
1 194506 . .
1 194509 0.1 . 2 194703 . .
2 194706 0.2 .
2 194709 0.1 0.05 2 194712 0.3 0.082 2 194803 0.2 0.082;
My attempt involves proc expand as follows. Yet, I'm not able to get the desired result. Moreover, I'm also getting the following warning: WARNING: The variable X has only 0 nonmissing observations, which is too few to apply the conversion method. The result series is set to missing.
Any help would be highly appreciated. Many thanks!
PROC EXPAND DATA=have OUT=want;
convert X=STDX / transformout=(MOVSTD 3 trim 2);
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.