Re: [程式] SAS取一個欄位的前兩個數字

看板Statistics作者 (somnambulist)時間15年前 (2010/04/15 12:43), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/2 (看更多)
data stacy; input ID $ region $; cards; 甲 2233 乙 2616 丙 3159 丁 6778 戊 231 ; run; data sacia; set stacy; if length(region) eq 4 then number=substr(left(region),1,2); else if length(region) eq 3 then number=substr(left(region),1,1); run; ※ 引述《hanjing (自知者明)》之銘言: : [軟體程式類別]: : SAS : [程式問題]: : 資料處理 : [軟體熟悉度]: : 低(1~3個月) : [問題敘述]: : 我想新創一個欄位,而新的欄位是對應到某一欄位內開頭的前兩個數字 : 像是 : ID 區域別 : 甲 2233 : 乙 2616 : 丙 3159 : 丁 6778 : 想得到的結果: : ID 區域別 新欄位 : 甲 2233 22 : 乙 2616 26 : 丙 3159 31 : 丁 6778 67 : 另外想請問,如果新欄位要的數字是某一欄位內開頭的前三個數字,指令是否一樣 : 非常感謝 -- If there is nothing left to burn, you have to set yourself on fire. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.11.193.244

04/15 13:56, , 1F
number = substr(left(region),1,length(region)-2) ;
04/15 13:56, 1F
文章代碼(AID): #1BnfboRk (Statistics)
文章代碼(AID): #1BnfboRk (Statistics)