




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、數(shù)據(jù)清理技術數(shù)據(jù)清理技術中國疾控中心衛(wèi)生統(tǒng)計室中國疾控中心衛(wèi)生統(tǒng)計室數(shù)據(jù)清洗數(shù)據(jù)清洗p從數(shù)據(jù)收集結束,到統(tǒng)計分析之前,需要對數(shù)據(jù)從數(shù)據(jù)收集結束,到統(tǒng)計分析之前,需要對數(shù)據(jù)做的清理工作做的清理工作數(shù)據(jù)清洗數(shù)據(jù)清洗p數(shù)據(jù)雙錄入對比數(shù)據(jù)雙錄入對比p數(shù)據(jù)合并數(shù)據(jù)合并p查找重復值查找重復值p查找缺失值查找缺失值p查找異常值查找異常值雙錄入對比雙錄入對比pExcelExcel用到的函數(shù):用到的函數(shù):pIfIf函數(shù)函數(shù)pIf(If(判斷條件判斷條件, ,條件滿足返回值條件滿足返回值, ,條件不滿足返回值條件不滿足返回值) )pexactexact函數(shù)函數(shù)比較兩個文本是否相同比較兩個文本是否相同pexact(
2、exact(比較文本比較文本1,1,比較文本比較文本2)2)poffsetoffset函數(shù)函數(shù)返回給定偏移量的新區(qū)域返回給定偏移量的新區(qū)域poffset(offset(參照區(qū)域參照區(qū)域, ,行行, ,列列) )雙錄入對比雙錄入對比psmall(small(數(shù)據(jù)區(qū)域數(shù)據(jù)區(qū)域, ,第幾小第幾小 ) ) 計算單元格范圍的第幾小的數(shù)值計算單元格范圍的第幾小的數(shù)值pColumn()Column()p返回單元格所在號返回單元格所在號pRow()Row()p返回單元格所在行號返回單元格所在行號雙錄入對比雙錄入對比pSASSAS命令命令:pproc compare base=proc compare ; ;p
3、by by 變量變量1 1 變量變量2 2 ; ;prun;run;雙錄入對比雙錄入對比pproc compareproc compare語句調用數(shù)據(jù)比較過程,選項語句調用數(shù)據(jù)比較過程,選項basebase和和comparecompare分別指定兩個比較和被比較的數(shù)據(jù)集;分別指定兩個比較和被比較的數(shù)據(jù)集;nosummarynosummary的作用是不顯示一些概括性的結果。的作用是不顯示一些概括性的結果。pbyby語句指定的變量有點類似于索引的作用,通常語句指定的變量有點類似于索引的作用,通常指定指定idid號。如果兩個數(shù)據(jù)集的觀測數(shù)不同,利用號。如果兩個數(shù)據(jù)集的觀測數(shù)不同,利用byby語句可以
4、保證它們比較的仍然是同一個語句可以保證它們比較的仍然是同一個idid號,號,而不會出現(xiàn)錯位比較的情況。而不會出現(xiàn)錯位比較的情況。雙錄入對比雙錄入對比pdata a1;data a1;pinput id g gender age marriage height weight nation;input id g gender age marriage height weight nation;pcards;cards;p(數(shù)據(jù))(數(shù)據(jù))p; ;pdata a2;data a2;pinput id g gender age marriage height weight nation;input id
5、 g gender age marriage height weight nation;pcards;cards;p(數(shù)據(jù))(數(shù)據(jù))p; ;pproc compare base=a1 compare=a2 nosummary;proc compare base=a1 compare=a2 nosummary;prun;run;雙錄入對比雙錄入對比雙錄入對比雙錄入對比查找缺失值查找缺失值pExcelExcel函數(shù):函數(shù):pIfIf函數(shù)函數(shù)pIf(If(判斷條件判斷條件, ,條件滿足返回值條件滿足返回值, ,條件不滿足返回值條件不滿足返回值) )pexactexact函數(shù)函數(shù)比較兩個文本是否相同比
6、較兩個文本是否相同pexact(exact(比較文本比較文本1,1,比較文本比較文本2)2)poffsetoffset函數(shù)函數(shù)返回給定偏移量的新區(qū)域返回給定偏移量的新區(qū)域poffset(offset(參照區(qū)域參照區(qū)域, ,行行, ,列列) )查找缺失值查找缺失值psmall(small(數(shù)據(jù)區(qū)域數(shù)據(jù)區(qū)域, ,第幾小第幾小 ) ) 計算單元格范圍的第幾小的數(shù)值計算單元格范圍的第幾小的數(shù)值pColumn()Column()p返回單元格所在號返回單元格所在號pRow()Row()p返回單元格所在行號返回單元格所在行號查找缺失值查找缺失值pSASSAS可用可用missingmissing函數(shù)實現(xiàn)函數(shù)實
7、現(xiàn)p如果結合數(shù)組和自動變量,可以一次性實現(xiàn)所有如果結合數(shù)組和自動變量,可以一次性實現(xiàn)所有變量缺失值的輸出變量缺失值的輸出查找缺失值查找缺失值pdata a1;data a1;pinput id g gender age marriage height weight nation;input id g gender age marriage height weight nation;pmiss_g=missing(g);miss_g=missing(g);pmiss_gender=missing(gender);miss_gender=missing(gender);pmiss_age=miss
8、ing(age);miss_age=missing(age);pmiss_marriage=missing(marriage);miss_marriage=missing(marriage);pmiss_height=missing(height);miss_height=missing(height);pmiss_weight=missing(weight);miss_weight=missing(weight);pmiss_nation=missing(nation);miss_nation=missing(nation);pcards;cards;p(數(shù)據(jù))(數(shù)據(jù))p;pproc pri
9、nt;proc print;prun;run;查找缺失值查找缺失值p部分結果部分結果查找缺失值查找缺失值p利用數(shù)組和自動變量利用數(shù)組和自動變量pdata missing;data missing;pset a;set a;parray chaarray cha* * _character_ ; _character_ ;pdo i=1 to dim(cha); do i=1 to dim(cha); pif missing(chai) then output;if missing(chai) then output;pend;end;parray numarray num* * _numeri
10、c_ ; _numeric_ ;pdo i=1 to dim(num); do i=1 to dim(num); pif missing(numi) then output;if missing(numi) then output;pend;end;pdrop i;drop i;pproc print;proc print;prun;run;查找缺失值查找缺失值p缺失值結果缺失值結果查找重復值查找重復值pExcelExcel函數(shù):函數(shù):pcountif(countif(計數(shù)區(qū)域計數(shù)區(qū)域, ,條件條件 ) ) 根據(jù)指定條件,在計數(shù)區(qū)域內計數(shù)根據(jù)指定條件,在計數(shù)區(qū)域內計數(shù)查找重復值查找重復值pSA
11、SSAS命令:命令:pproc sort out=proc sort ; ;pby by 變量變量1 1 變量變量2 2 ; ;prun;run;查找重復值查找重復值pproc sortproc sort語句調用排序過程。選項語句調用排序過程。選項out=out=數(shù)據(jù)集指定排序數(shù)據(jù)集指定排序后的數(shù)據(jù)集名。因為排序后數(shù)據(jù)發(fā)生了變化,因此可指定后的數(shù)據(jù)集名。因為排序后數(shù)據(jù)發(fā)生了變化,因此可指定該選項將排序后的數(shù)據(jù)存放到一個新的數(shù)據(jù)集中。如果不該選項將排序后的數(shù)據(jù)存放到一個新的數(shù)據(jù)集中。如果不加該選項,排序后的數(shù)據(jù)集將覆蓋原有數(shù)據(jù)集,這樣你就加該選項,排序后的數(shù)據(jù)集將覆蓋原有數(shù)據(jù)集,這樣你就找不回原
12、有的未排序的數(shù)據(jù)了。找不回原有的未排序的數(shù)據(jù)了。p選項選項nodupkeynodupkey表示如果表示如果byby語句指定的排序變量有重復值,語句指定的排序變量有重復值,則刪除重復值。如按則刪除重復值。如按idid排序,如果排序,如果idid有重復值,則只保留有重復值,則只保留重復值中的第一個值,刪除其它值。重復值中的第一個值,刪除其它值。p選項選項nouniquekeynouniquekey的作用跟的作用跟nodupkeynodupkey正好相反,如果正好相反,如果byby語語句指定的排序變量都是唯一值,則將其刪除。如按句指定的排序變量都是唯一值,則將其刪除。如按idid排序排序,如果,如果
13、idid沒有有重復值,則全部刪除。沒有有重復值,則全部刪除。查找重復值查找重復值pbyby語句指定排序的變量,可以指定多個。選項語句指定排序的變量,可以指定多個。選項descendingdescending表示按降序排序,如果不加該選項,表示按降序排序,如果不加該選項,默認的是按升序排序。默認的是按升序排序。p當需要查找重復值時,當需要查找重復值時,byby語句指定的變量就是需語句指定的變量就是需要查找的重復值變量。要查找的重復值變量。查找重復值查找重復值pdata a1;data a1;pinput id g gender age marriage height weight nation;
14、input id g gender age marriage height weight nation;pcards;cards;p(數(shù)據(jù))(數(shù)據(jù))p;pproc sort proc sort nouniquekeynouniquekey out=bb; out=bb;pby genderby gender age marriage height weight;age marriage height weight;prun;run;pproc print data=bb;proc print data=bb;prun;run;查找重復值查找重復值p5 5個變量均重復的觀測個變量均重復的觀測查找
15、異常值查找異常值pExcelExcel函數(shù):函數(shù):pIfIf函數(shù)函數(shù)pIf(If(判斷條件判斷條件, ,條件滿足返回值條件滿足返回值, ,條件不滿足返回值條件不滿足返回值) )p結合各種算術運算符、比較運算符、邏輯運算符等結合各種算術運算符、比較運算符、邏輯運算符等查找異常值查找異常值p常見運算符常見運算符符號符號說明說明示例示例+和和-加減運算加減運算=3+2-4=1*和和/乘除運算乘除運算=3*2/4=1.5乘冪乘冪=32=9,=16(1/2)=4=、=、=等于、不等于等于、不等于大于、小于大于、小于大于等于、小于等于大于等于、小于等于=(A2=9),判斷,判斷A2是否等于是否等于9=(A
16、29),判斷,判斷A2是否不等于是否不等于9=(A2=9),判斷,判斷A2是否大于等于是否大于等于9and多個表達式同時成立多個表達式同時成立 and(A19,B19,B1(大于)、 =(大于等于)、 =(小于等于)in,表示其中之一,如grade in(2,4,6)表示只要是grade為2、4、6中的其中一個就算符合條件;dept not in(“A”, “B”)表示只要dept不是“A”或“B”就算成立&或and(表示2個表達式同時成立) | 或or(表示兩個表達式至少一個成立)查找異常值查找異常值pdata a1;data a1;pinput id g gender age ma
17、rriage height weight nation;input id g gender age marriage height weight nation;pcards;cards;p(數(shù)據(jù))(數(shù)據(jù))p;pdata b1;data b1;pset a1;set a1;pif if (gender not in(1,2) (gender not in(1,2) | | (age=60) (age=60) | | (height=200) (height=200) | | (weight=100) (weight=100) p| | (marriage not in (1,0) (marria
18、ge not in (1,0) | | (nation not in (1,2)(nation not in (1,2); ;pproc print;proc print;prun;run;查找異常值查找異常值查找異常值查找異常值pdata b2;data b2;pset a1;set a1;pif (gender not in(1,2,.) |if (gender not in(1,2,.) |p(age=. and (age=60) | (age=. and (age=60) | p(height=. and(height=200) |(height=. and(height=200) |
19、p(weight=. and (weight=100)| (weight=. and (weight=100)| pmarriage not in (1,0,.) | marriage not in (1,0,.) | pnation not in (1,2,.);nation not in (1,2,.);pproc print;proc print;prun;run;查找異常值查找異常值查找異常值查找異常值pdata data gendergender(where=(gender not in(1,2,.) (where=(gender not in(1,2,.) pageage(wher
20、e=(not missing(age) and(age=50) (where=(not missing(age) and(age=50) pmarriagemarriage(where=(marriage not in(1,0,.) (where=(marriage not in(1,0,.) pheightheight(where=(not missing(height) and(height=150 or (where=(not missing(height) and(height=200)height=200)pweightweight(where=(not missing(weight) and(weight=40 or (where=(not missing(weight) and(weight=100) weight=100) pnationnation(where=(nation not in(1,2,.) ;(where=(nation not in(1,2,.)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年高效酸霧凈化器項目資金需求報告代可行性研究報告
- 2025科研設備租賃合同樣本
- 2025娛樂場所員工勞動合同書模板
- 2025合肥服務合同范本
- 2025年北京市勞動合同樣本
- 2025二手車買賣合同
- 2025新款企業(yè)辦公房產租賃合同
- 2025年簽訂的違章建筑房屋租賃合同是否有效
- 2025企業(yè)合同轉讓協(xié)議
- 2025年的擔保公司貸款合同范本
- 2025屆上海市浦東新區(qū)高三二模英語試卷(含答案)
- 開曼群島公司法2024版中文譯本(含2024年修訂主要內容)
- 【MOOC】航空燃氣渦輪發(fā)動機結構設計-北京航空航天大學 中國大學慕課MOOC答案
- 悅己人生-大學生心理健康智慧樹知到期末考試答案章節(jié)答案2024年哈爾濱工業(yè)大學
- 職業(yè)衛(wèi)生評價考試計算題匯總
- JJF 1318-2011 影像測量儀校準規(guī)范-(高清現(xiàn)行)
- 5711裝備質量問題處理通用要求
- 酸洗磷化線材項目建議書范文
- 中山大學教授和副教授職務聘任實施辦法(試行)
- 恒速傳動裝置的工作原理
- 住院病歷交接登記本
評論
0/150
提交評論