1

テキスト内のスペースをアンダースコアに変更する必要がありますが、数字間のスペースではなく、単語間のスペースのみです。たとえば、

"The quick brown fox 99 07 3475"

なるだろう

"The_quick_brown_fox 99 07 3475"

これをデータステップで使用してみました:

mytext = prxchange('s/\w\s\w/_/',-1,mytext);

しかし、結果は私が望んでいたものではありませんでした

"Th_uic_row_ox 99 07 3475"

私ができることについてのアイデアはありますか?

前もって感謝します。

4

3 に答える 3

7
Data One ;
X = "The quick brown fox 99 07 3475" ;
Y = PrxChange( 's/(?<=[a-z])\s+(?=[a-z])/_/i' , -1 , X ) ;
Put X= Y= ;
Run ;
于 2012-08-24T15:30:58.597 に答える
3

「W W」を「W_W」に変更したい場合、「W W」を「_」に変更しています。

だから prxchange('s/(\w)\s(\w)/$1_$2/',-1,mytext);

完全な例:

 data test;
mytext='The quick brown fox 99 07 3475';
newtext = prxchange('s/([A-Za-z])\s([A-Za-z])/$1_$2/',-1,mytext);
put _all_;
run;
于 2012-08-24T15:18:58.123 に答える
1

CALL PRXNEXT 関数を使用して各一致の位置を見つけてから、SUBSTR 関数を使用してスペースをアンダースコアに置き換えることができます。\w は任意の英数字に一致するため、正規表現を変更したので、数字の間にスペースを含める必要があります。その式を使用してどのように結果を得たのかわかりません。とにかく、以下のコードはあなたが望むものを与えるはずです。

data have;
mytext='The quick brown fox 99 07 3475';
_re=prxparse('/[a-z]\s[a-z]/i'); /* match a letter followed by a space followed by a letter, ignore case */
_start=1 /* starting position for search */;
call prxnext(_re,_start,-1,mytext,_position,_length); /* find position of 1st match */
    do while(_position>0); /* loop through all matches */
        substr(mytext,_position+1,1)='_'; /* replace ' ' with '_' for matches */
        _start=_start-2; /* prevents the next start position jumping 3 ahead (the length of the regex search string) */
        call prxnext(_re,_start,-1,mytext,_position,_length); /* find position of next match */ 
end;
drop _: ;
run;
于 2012-08-24T15:17:17.627 に答える