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

熱線電話:13121318867

登錄
首頁精彩閱讀sas正則式之prxparen
sas正則式之prxparen
2017-04-03
收藏

sas正則式之prxparen

今天還是要繼續(xù)正則式的內(nèi)容,這周的內(nèi)容是prxparen函數(shù),這個函數(shù)我個人覺得特別有用,是因?yàn)樗汀皘”結(jié)合使用可以同時(shí)容納很多種情況的字符串。

prxparse這個函數(shù)沒有什么參數(shù),就是填入prxparse正則式的字符返回對應(yīng)的是praparse的哪一部分。我現(xiàn)在說你肯定很懵逼,來,我們舉個栗子!

re=prxparse("/(one)|(two)|(three)/")

position=prxmatch(re,string)

就是這么說prxparse("/(one)|(two)|(three)/")搜索字符函數(shù)中/(one)|(two)|(three)/ 用“|”分開了三個即將要搜索的字符,即‘’one”為第一個搜索字符,一旦在字符中發(fā)現(xiàn)“one”了就返回1,假設(shè)第一個發(fā)現(xiàn)的字符串是“three”就是返回3,所以返回剛才的例子就很容易理解了。


現(xiàn)在用一個小例子再介紹這個函數(shù)

data paren;

if _n_=1 then pattern=prxparse("/(\d )|(\d\d )|(\d\d\d )/");

retain pattern;

input string $char30.;

position=prxmatch(pattern,string);

if position gt 0 then which_paren=prxparen(pattern);

datalines;

one single digit 8 here

two 888 77

12345 1234 123 12 1

;

run;

結(jié)果:

如圖所示,position是函數(shù)prxmatch的返回結(jié)果,即字符的位置,which_paren是prxparen的返回結(jié)果,即對應(yīng)的是字符搜索的哪一部分。if position gt 0 then which_paren=prxparen(pattern); 這里的if是為了確認(rèn)是prxmatch搜索到位置的時(shí)候才判斷字符是屬于pattern的哪一部分。

現(xiàn)在用一個實(shí)際數(shù)據(jù)處理中的例子再深化這個函數(shù)。

這是一份領(lǐng)導(dǎo)給我的數(shù)據(jù),可以看到數(shù)據(jù)上中文字符之后還有一些亂七八糟的英文啊符號啊數(shù)字啊,當(dāng)時(shí)領(lǐng)導(dǎo)的需求是,把這份數(shù)據(jù)清洗出來變成只用字符的變量以及不要用類似“黃山分行”這種字眼的存在。所以當(dāng)下就寫了以下這段代碼解決的這個需求。來,上代碼!

data ss;

set dd;

if _n_=1 then

ret=prxparse("/(\D?\銀行)|(\D?\金融)|(\D?\貸款)|(\D?\融資)|(\D?\保險(xiǎn))|(\D?\擔(dān)保)|(\D?\信用[社合聯(lián)])/");

retain ret;

position=prxmatch(ret,QUERY_OPERATOR);

if position gt 0 then which_posit=prxparen(ret);

else which_posit=0;

if which_posit gt 0 then do;

call prxsubstr(ret,QUERY_OPERATOR,start,length);

if start gt 0 and which_posit=1 then do;

dd=substr(QUERY_OPERATOR,1,start)||"銀行";

end;

if start gt 0 and which_posit=2 then do;

dd=substr(QUERY_OPERATOR,1,start)||"金融公司";

end;

if start gt 0 and which_posit=3 then do;

dd=substr(QUERY_OPERATOR,1,start)||"貸款公司";

end;

if start gt 0 and which_posit=4 then do;

dd=substr(QUERY_OPERATOR,1,start)||"融資有限公司";

end;

if start gt 0 and which_posit=5 then do;

dd=substr(QUERY_OPERATOR,1,start)||"保險(xiǎn)有限公司";

end;

if start gt 0 and which_posit=6 then do;

dd=substr(QUERY_OPERATOR,1,start)||"擔(dān)保公司";

end;

if start gt 0 and which_posit=7 then do;

dd=substr(QUERY_OPERATOR,1,start)||"農(nóng)村信用合作社";

end;

end;

else dd='其他';

drop start length which_posit position ret;

run;

結(jié)果:

現(xiàn)在單獨(dú)取一個if語句的下的執(zhí)行語句介紹一下:

call prxsubstr(ret,QUERY_OPERATOR,start,length);

if start gt 0 and which_posit=1 then do;

dd=substr(QUERY_OPERATOR,1,start)||"銀行";

end;

call prxsubstr 在之前的文章中已經(jīng)介紹過了,所以如果忘了,再翻一下。然后if start gt 0 and which_posit=1 then do ;這個語句中的which_posit=1 即就是搜索到“銀行”兩個字就是認(rèn)定這個機(jī)構(gòu)就是銀行卡,然后就截取“銀行”前面的那一串字,然后再接上“銀行”兩個字。這里你會問,問什么長度為什么用的是“start”這個變量,因?yàn)槲覀兯阉鞯氖恰便y行”兩個字,所以返回的位置是銀行的位置,但是我們需要的是“銀行”前面的那一串字符,所以就使用start作為長度。數(shù)據(jù)分析師培訓(xùn)

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

若不方便掃碼,搜微信號: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)的第一個參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(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); }