作者faceoflove56 (1234567)
看板Statistics
标题[程式] SAS中LAG程式无法用在if...then
时间Wed Jun 17 11:15:31 2015
[软体程式类别]:
SAS
[程式问题]:
目前遇到一个问题
lag函数无法用再if...then语法中
但我想把资料整理成
Name Nth
---------------------
ID1 0
ID1 1
ID1 2
ID2 0
ID2 1
ID2 2
ID2 3
我原先使用的语法为
data
set
if first.name then Nth=0;
if Name=lag(Name) then Nth=Lag(Nth)+1;
run;
想请问该如何修改,感谢。
[软体熟悉度]:
低(1~3个月)
[问题叙述]:
Lag函数无法应用於if...then
[程式范例]:
已贴在程式问题
-----------------------------------------------------------------------------
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.119.120.6
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Statistics/M.1434510934.A.962.html
※ 编辑: faceoflove56 (140.119.120.6), 06/17/2015 11:16:16
1F:推 BugEater: LAG is called in conditional code, the value it 06/17 12:01
2F:→ BugEater: returened is not the value from the previous 06/17 12:02
3F:→ BugEater: but is the value of its previous execution. 06/17 12:03
4F:→ BugEater: try this. data A;set A; by name; 06/17 12:04
5F:→ BugEater: if first.name then Nth=0; 06/17 12:06
6F:→ BugEater: Nth=Lag(Nth)+1;run; 06/17 12:07
7F:→ faceoflove56: 感谢>"< 06/18 13:00
8F:→ luenchang: It's not recommended to use LAG() within a logical 06/19 02:38
9F:→ luenchang: condition (i.e. if then). Check out how the LAG() 06/19 02:39
10F:→ luenchang: works in this article 06/19 02:40
11F:→ luenchang: "Please Don't Lag Behind LAG! " 06/19 02:40