99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀利用SAS進(jìn)行數(shù)據(jù)清洗技術(shù)—缺失值查詢
利用SAS進(jìn)行數(shù)據(jù)清洗技術(shù)—缺失值查詢
2016-06-10
收藏

利用SAS進(jìn)行數(shù)據(jù)清洗技術(shù)—缺失值查詢

數(shù)據(jù)清洗技術(shù)是統(tǒng)計(jì)分析之前必做的一步,而且也是非常麻煩的一步,有時(shí)甚至花費(fèi)的時(shí)間比統(tǒng)計(jì)分析都長。所以沒有一定的技巧,這將是個(gè)非常煩人的工作。本篇文章介紹如何利用sas進(jìn)行缺失值的查詢工作。

假定我們有數(shù)據(jù)集aa,包含如下變量(數(shù)據(jù)省略):

ID dose gender age t0 t1 a1 a2

最簡單的方式當(dāng)然就是挨個(gè)變量找缺失值,如下:

data missing;

set aa;

if id=. or dose=. or gender=. or age=. or t0=. or t1=. or a1=. or a2=.;

proc print;

run;

這種方式很好理解,就是利用if語句逐個(gè)判斷每個(gè)變量是否有缺失(注意,如果變量時(shí)文本型,不能寫=.,而是=" "),但缺點(diǎn)也是顯而易見的,如果不是現(xiàn)在的8個(gè)變量,而是80個(gè)變量,那寫一遍估計(jì)要累個(gè)半死。所以我們用下面的語句節(jié)省體力:

data missing(drop=i);

set aa;

array num{8} id dose gender age t0 t1 a1 a2;

do i=1 to 8;

if num{i}=. then output;

end;

這種方式好像比上面的更復(fù)雜了,但效率提高了n倍(取決于你的變量有多少)。這種方式是利用數(shù)組判斷缺失值,不管有100個(gè)還是1000個(gè)變量,對數(shù)組來說沒什么區(qū)別,只是數(shù)組中變量的個(gè)數(shù)改變一下而已(如本例中的8)。

當(dāng)這種方式仍不是最節(jié)省的,因?yàn)槲覀冞€是需要把這8個(gè)變量一一寫出來,那可不可以就不寫變量名呢。當(dāng)然可以,還有更簡單的方式如下:

data missing(drop=i);

set aa;

array num{*} _all_;

do i=1 to dim(num);

if num{i}=. then output;

end;

當(dāng)這種方式更簡單了,而且是個(gè)通用語句,不管你有10個(gè)還是1000個(gè)變量,都可以用這種方式來查詢,一個(gè)字母都不用改。當(dāng)然前提是所有變量都是數(shù)值型,如果是文本型,那就應(yīng)該是num{i}=" "。

還有另外一種非常簡潔 的方式是利用函數(shù),如下:

data missing(drop=i);

set aa;

array num{*} _all_;

do i=1 to dim(num);

if missing(num{i}) then output;

end;

函數(shù)的這種方式有什么好處呢?起碼有一點(diǎn),你不用考慮到底是數(shù)值還是文本,全部都是missing(變量)就行了。否則你還得想著數(shù)值是.,文本是" "。一不小心忘了容易出問題。

前面所說的都是假定所有變量都是同一種類型的,如果變量中既有數(shù)值型,又有文本型,那怎么辦呢?如下程序就很簡單了:

data missing(drop=i);

set aa;

array a _numeric_;

do i=1 to dim(a);

if missing(a) then output;

end;

array b_character_;

do i=1 to dim(b);

if missing(b) then output;

end;

毫不夸張地說,這個(gè)簡直就是個(gè)缺失值的通用語句,同時(shí)遍歷了數(shù)據(jù)集中的數(shù)值型和文本型的所有缺失值。所有的缺失值查找,幾乎都可以這一語句來實(shí)現(xiàn),它幾乎包含了所有的可能情況,還能苛求什么呢?套用就行了。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號(hào):CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }