Re: [問題] sas 依照分群新增變數

看板Statistics作者 (..)時間15年前 (2010/12/08 17:59), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/5 (看更多)
※ 引述《mulala (MM)》之銘言: : obs id var1 var2 : 1 1 1 1 : 2 1 2 1 : 3 1 3 1 : 4 1 1 2 : 5 1 2 2 : 6 2 1 1 : 7 2 2 1 : 8 2 1 2 : 9 2 2 2 : 10 2 3 2 : 已知id,var1 : 想請問如何根據id做區分以新增var2 改自13051 socery大的程式 假設資料是 data a;input id var1; cards; 1 1 1 2 1 3 1 1 1 2 2 1 2 2 2 1 2 2 2 3 ; run; data a1; set a;by id;n=1; if first.id then do; if n=1 then var2=1; retain var2;end; else if var1=1 then var2=var2+1; if last.id then ;drop n; run; 參考看看~~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.118.18 ※ 編輯: imaltar 來自: 140.112.118.18 (12/08 17:59)
文章代碼(AID): #1C_rRhyI (Statistics)
討論串 (同標題文章)
文章代碼(AID): #1C_rRhyI (Statistics)