Several comments:
1. You can use parentheses in the USE and CREATE statements to tell SAS/IML that the data set name is not a literal value but is the value contained in a variable.
2. Currently, each call to the EWMA_VAR function overwrites the S_VAR data set. You can pass in an output data set name, if that's not what you want.
3. You need to pass in the name of the data step and the name of the variables as a string by using quotation marks.
4. It looks like you are trying to create an exponentially weighted moving average. If so, see the article, "Rolling statistics in SAS/IML."
data step2;
input GDP DEP QE;
datalines;
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
;
PROC IML;
START ewma_var(ds,in_var,length);
USE (ds); READ ALL VAR in_var INTO r_var; close;
n=nrow(r_var);
s_var=j(n,1,.);
DO a=1 TO n;
IF a=1 THEN DO;
s_var[a,1] = r_var[a,1];
END;
IF a >1 THEN DO;
s_var[a,1] = ((r_var[a,1]-s_var[a-1,1])*(2/length+1))+s_var[a-1,1];
END;
END;
CREATE s_var FROM s_var [COLNAME = 's_var']; APPEND FROM s_var; close;
FINISH;
CALL ewma_var("step2","GDP",8);
CALL ewma_var("step2","GDP",4);
CALL ewma_var("step2","DEP",2);
CALL ewma_var("step2","QE",10);
QUIT;
... View more