I'm trying to write an IML function where one of the parameters is a dataset and I am trying to avoid having to use the SAS macro language in order to accomplish this task. The dataset I'm looking to pass into the function is called "step2". The following is my attempt. PROC IML; START ewma_var(ds,in_var,length); USE ds; READ ALL VAR {in_var} INTO r_var; 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; FINISH; CALL ewma_var(step2,GDP,8); QUIT; So I want the parameter "ds" to be "step2", the parameter "in_var" to be a variable contained in "step2", and "length" to be a numeric used to calculate the weighting factor. That way I could then do the following. PROC IML; START ewma_var(ds,in_var,length); USE ds; READ ALL VAR {in_var} INTO r_var; 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; 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