标题: lag函数的用法样例 [打印本页] 作者: shiyiming 时间: 2007-9-1 07:36 标题: lag函数的用法样例 [code:5f8d9]/***************************************************************************/
/* This program generates up to three lagged values. By increasing the */
/* size of the array and the number of assignment statements that use */
/* the LAGn functions, you can generate as many lagged values as needed. */
/***************************************************************************/
/* Create and assign values to three new variables. Use ENDLAG1- */
/* ENDLAG3 to store lagged values of END, from the most recent to the */
/* third preceding value. */
array x(*) endlag1-endlag3;
endlag1=lag1(end);
endlag2=lag2(end);
endlag3=lag3(end);
/* Reset COUNT at the start of each new BY-Group */
if first.start then count=1;
/* On each iteration, set array elements that have */
/* not yet received a lagged value for the current */
/* BY-Group to missing. Increase count by 1. */
do i=count to dim(x);
x(i)=.;
end;
count + 1;
run;