作者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/m.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