看板 Statistics 關於我們 聯絡資訊
[軟體程式類別]: 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://www.ptt.cc/bbs/Statistics/M.1434510934.A.962.html ※ 編輯: faceoflove56 (140.119.120.6), 06/17/2015 11:16:16
BugEater: LAG is called in conditional code, the value it 06/17 12:01
BugEater: returened is not the value from the previous 06/17 12:02
BugEater: but is the value of its previous execution. 06/17 12:03
BugEater: try this. data A;set A; by name; 06/17 12:04
BugEater: if first.name then Nth=0; 06/17 12:06
BugEater: Nth=Lag(Nth)+1;run; 06/17 12:07
faceoflove56: 感謝>"< 06/18 13:00
luenchang: It's not recommended to use LAG() within a logical 06/19 02:38
luenchang: condition (i.e. if then). Check out how the LAG() 06/19 02:39
luenchang: works in this article 06/19 02:40
luenchang: "Please Don't Lag Behind LAG! " 06/19 02:40