SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 937|回复: 0
打印 上一主题 下一主题

lag函数的用法样例

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2007-9-1 07:36:40 | 只看该作者

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 starting data */  

data old;
  input start end;
datalines;
1 1
1 2
1 3
1 4
1 5
1 6
1 7
2 1
2 2
3 1
3 2
3 3
3 4
3 5
;

data new(drop=i count);
  set old;
  by start;

  /* 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;

proc print;
run;[/code:5f8d9]
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-4 07:13 , Processed in 0.071382 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表