Statistics 板


LINE

※ 引述《liton (歐吉桑留學生)》之銘言: : 幫朋友想些SAS的程式該如何寫 : 目前有個data set(source) : 共6個欄位 (i,j,k,l,m,n 數字整數格式 已經由小到大排列) : 想篩選出以下條件的資料 : (1).二個3連, : 例, 2,3,4+11,12,13 : (2).三個2連, : 例, 11,12+22,23+35,36 : (3).3單連+3偶連, : 例, 3,5,7+12,14,16 : (4).2單連+2單連+2偶連或2單連+2偶連+2偶連的組合, : 例, 3,5+11,13+30,32或2,4+10,12+33,35 : 我有想過用array寫 : 但是array還是逃不出要指定哪些欄位符合條件 : 例如第一題中 我必須程式中有寫到k-j, j-i : 但是這樣的解題方法到了第二題之後只會撞牆 : 不知道有啥比較好的解法呢? (2) data aa; set aa; a1=j-i; a2=k-j; a3=l-k; a4=m-l; a5=n-m; if a1^=1 then a1=0; if a2^=1 then a2=0; if a3^=1 then a3=0; if a4^=1 then a4=0; if a5^=1 then a5=0; data bb; set aa; if a1=1 and a2=0 and a3=1 and a4=0 and a5=1 then output; keep i j k l m n; run; 三個2連,所以a1-a5應該要 [1 0 1 0 1] 的樣子才滿足 (3) data aa; set aa; b1=j-i; b2=k-j; b3=m-l; b4=n-m; if b1^=2 then b1=0; if b2^=2 then b2=0; if b3^=2 then b3=0; if b4^=2 then b4=0; b5=k/2; b6=ceil(b5); if b5^=b6 then b7=1 ; else b7=0; *b7=1 k為奇數*; b8=l/2; b9=ceil(b8); if b8=b9 then b10=1 ; else b10=0; *b10=1 l為偶數*; data cc; set aa; if b1=2 and b2=2 and b3=2 and b4=2 and b7=1 and b10=1 then output; keep i j k l m n; run; 3單連+3偶連 所以b1-b4應該是 [2 2 2 2] 的樣子才滿足 另外要驗證前三個是奇數 後三個是偶數 (只要三個裡面有一個滿足可以,不然b1-b4不會滿足 [2 2 2 2] ) 因為不知道SAS有沒有直接看是不是奇數偶數的函數 所以小繞了一圈 (4) data dd; set aa; a1=j-i; a2=k-j; a3=l-k; a4=n-m; if a1^=2 then a1=0; if a2^=2 then a2=0; if a3^=2 then a3=0; if a4^=2 then a4=0; b1=j/2; b2=ceil(b1); if b1^=b2 then b3=1 ; else b3=0; *b3=1 j為奇數*; b4=l/2; b5=ceil(b4); if b4^=b5 then b6=1 ; else b6=0; *b6=1 k為奇數*; b7=n/2; b8=ceil(b7); if b7=b8 then b9=1 ; else b9=0; *b9=1 l為偶數*; if a1=2 and a2=0 and a3=2 and a4=2 and b3=1 and b6=1 and b9=1 then output; keep i j k l m n; data ee; set aa; a1=j-i; a2=l-k; a3=m-l; a4=n-m; if a1^=2 then a1=0; if a2^=2 then a2=0; if a3^=2 then a3=0; if a4^=2 then a4=0; b1=j/2; b2=ceil(b1); if b1^=b2 then b3=1 ; else b3=0; *b3=1 j為奇數*; b4=l/2; b5=ceil(b4); if b4=b5 then b6=1 ; else b6=0; *b6=1 k為偶數*; b7=n/2; b8=ceil(b7); if b7=b8 then b9=1 ; else b9=0; *b9=1 n為偶數*; if a1=2 and a2=2 and a3=0 and a4=2 and b3=1 and b6=1 and b9=1 then output; keep i j k l m n; data ff; set dd ee; run; 2單連+2單連+2偶連 跟 2單連+2偶連+2偶連 分開做在合併 邏輯跟上面大同小異 沒有data可以檢查寫的對不對, 也許有小錯誤在裡面,或是沒考慮周全的 --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.145.80 ※ 編輯: MmmRrrrX 來自: 140.119.145.80 (04/07 05:03) ※ 編輯: MmmRrrrX 來自: 140.119.145.80 (04/07 13:40)







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Gossiping站內搜尋

TOP