版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、數(shù)據(jù)清理技術(shù)數(shù)據(jù)清理技術(shù)中國疾控中心衛(wèi)生統(tǒng)計室中國疾控中心衛(wèi)生統(tǒng)計室數(shù)據(jù)清洗數(shù)據(jù)清洗p從數(shù)據(jù)收集結(jié)束,到統(tǒng)計分析之前,需要對數(shù)據(jù)從數(shù)據(jù)收集結(jié)束,到統(tǒng)計分析之前,需要對數(shù)據(jù)做的清理工作做的清理工作數(shù)據(jù)清洗數(shù)據(jù)清洗p數(shù)據(jù)雙錄入對比數(shù)據(jù)雙錄入對比p數(shù)據(jù)合并數(shù)據(jù)合并p查找重復(fù)值查找重復(fù)值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語句調(diào)用數(shù)據(jù)比較過程,選項語句調(diào)用數(shù)據(jù)比較過程,選項basebase和和comparecompare分別指定兩個比較和被比較的數(shù)據(jù)集;分別指定兩個比較和被比較的數(shù)據(jù)集;nosummarynosummary的作用是不顯示一些概括性的結(jié)果。的作用是不顯示一些概括性的結(jié)果。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如果結(jié)合數(shù)組和自動變量,可以一次性實現(xiàn)所有如果結(jié)合數(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部分結(jié)果部分結(jié)果查找缺失值查找缺失值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缺失值結(jié)果缺失值結(jié)果查找重復(fù)值查找重復(fù)值pExcelExcel函數(shù):函數(shù):pcountif(countif(計數(shù)區(qū)域計數(shù)區(qū)域, ,條件條件 ) ) 根據(jù)指定條件,在計數(shù)區(qū)域內(nèi)計數(shù)根據(jù)指定條件,在計數(shù)區(qū)域內(nèi)計數(shù)查找重復(fù)值查找重復(fù)值pSA
11、SSAS命令:命令:pproc sort out=proc sort ; ;pby by 變量變量1 1 變量變量2 2 ; ;prun;run;查找重復(fù)值查找重復(fù)值pproc sortproc sort語句調(diào)用排序過程。選項語句調(diào)用排序過程。選項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語句指定的排序變量有重復(fù)值,語句指定的排序變量有重復(fù)值,則刪除重復(fù)值。如按則刪除重復(fù)值。如按idid排序,如果排序,如果idid有重復(fù)值,則只保留有重復(fù)值,則只保留重復(fù)值中的第一個值,刪除其它值。重復(fù)值中的第一個值,刪除其它值。p選項選項nouniquekeynouniquekey的作用跟的作用跟nodupkeynodupkey正好相反,如果正好相反,如果byby語語句指定的排序變量都是唯一值,則將其刪除。如按句指定的排序變量都是唯一值,則將其刪除。如按idid排序排序,如果,如果
13、idid沒有有重復(fù)值,則全部刪除。沒有有重復(fù)值,則全部刪除。查找重復(fù)值查找重復(fù)值pbyby語句指定排序的變量,可以指定多個。選項語句指定排序的變量,可以指定多個。選項descendingdescending表示按降序排序,如果不加該選項,表示按降序排序,如果不加該選項,默認(rèn)的是按升序排序。默認(rèn)的是按升序排序。p當(dāng)需要查找重復(fù)值時,當(dāng)需要查找重復(fù)值時,byby語句指定的變量就是需語句指定的變量就是需要查找的重復(fù)值變量。要查找的重復(fù)值變量。查找重復(fù)值查找重復(fù)值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;查找重復(fù)值查找重復(fù)值p5 5個變量均重復(fù)的觀測個變量均重復(fù)的觀測查找
15、異常值查找異常值pExcelExcel函數(shù):函數(shù):pIfIf函數(shù)函數(shù)pIf(If(判斷條件判斷條件, ,條件滿足返回值條件滿足返回值, ,條件不滿足返回值條件不滿足返回值) )p結(jié)合各種算術(shù)運算符、比較運算符、邏輯運算符等結(jié)合各種算術(shù)運算符、比較運算符、邏輯運算符等查找異常值查找異常值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多個表達(dá)式同時成立多個表達(dá)式同時成立 and(A19,B19,B1(大于)、 =(大于等于)、 =(小于等于)in,表示其中之一,如grade in(2,4,6)表示只要是grade為2、4、6中的其中一個就算符合條件;dept not in(“A”, “B”)表示只要dept不是“A”或“B”就算成立&或and(表示2個表達(dá)式同時成立) | 或or(表示兩個表達(dá)式至少一個成立)查找異常值查找異常值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)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 易錯題17 文言文閱讀之?dāng)嗑漕}-當(dāng)斷不斷不該斷卻斷【高考語文】備戰(zhàn)2025年高考易錯題(新高考專用)含解析
- 參觀圓明園的觀后感
- 智能大廈綜合布線的工程設(shè)計方案
- 青春追夢人心共進(jìn)
- 多振源混疊的DAS目標(biāo)信號分離
- 智研咨詢發(fā)布:2024年中國美妝行業(yè)市場發(fā)展環(huán)境及前景研究報告
- DOPS基P-N-S協(xié)同阻燃劑的合成及其阻燃環(huán)氧樹脂的性能研究
- 二零二五版國際學(xué)校英語教師兼職外教聘請合同樣本3篇
- 基于免疫和動態(tài)載荷調(diào)節(jié)機(jī)理的骨折愈合模型建模與仿真
- 基于多特征融合的轉(zhuǎn)轍機(jī)退化狀態(tài)識別與預(yù)測研究
- 房地產(chǎn)調(diào)控政策解讀
- 物業(yè)民法典知識培訓(xùn)課件
- 2023年初中畢業(yè)生信息技術(shù)中考知識點詳解
- 2024-2025學(xué)年八年級數(shù)學(xué)人教版上冊寒假作業(yè)(綜合復(fù)習(xí)能力提升篇)(含答案)
- 《萬方數(shù)據(jù)資源介紹》課件
- 《AP內(nèi)容介紹》課件
- 醫(yī)生定期考核簡易程序述職報告范文(10篇)
- 第一章-地震工程學(xué)概論
- QUALITY MANUAL質(zhì)量手冊(英文版)
- 了不起的狐貍爸爸-全文打印
- 建筑力學(xué)ppt課件(完整版)
評論
0/150
提交評論