[程式] SAS中LAG程式無法用在if...then

看板Statistics作者 (1234567)時間9年前 (2015/06/17 11:15), 9年前編輯推噓1(1010)
留言11則, 3人參與, 最新討論串1/2 (看更多)
[軟體程式類別]: 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

06/17 12:01, , 1F
LAG is called in conditional code, the value it
06/17 12:01, 1F

06/17 12:02, , 2F
returened is not the value from the previous
06/17 12:02, 2F

06/17 12:03, , 3F
but is the value of its previous execution.
06/17 12:03, 3F

06/17 12:04, , 4F
try this. data A;set A; by name;
06/17 12:04, 4F

06/17 12:06, , 5F
if first.name then Nth=0;
06/17 12:06, 5F

06/17 12:07, , 6F
Nth=Lag(Nth)+1;run;
06/17 12:07, 6F

06/18 13:00, , 7F
感謝>"<
06/18 13:00, 7F

06/19 02:38, , 8F
It's not recommended to use LAG() within a logical
06/19 02:38, 8F

06/19 02:39, , 9F
condition (i.e. if then). Check out how the LAG()
06/19 02:39, 9F

06/19 02:40, , 10F
works in this article
06/19 02:40, 10F

06/19 02:40, , 11F
"Please Don't Lag Behind LAG! "
06/19 02:40, 11F
文章代碼(AID): #1LWEPMbY (Statistics)
文章代碼(AID): #1LWEPMbY (Statistics)