2013-11-21 42 views
1

清洗細胞我有一個表如何使用正則表達式SAS

id Attribute       Other 
1 Written Jan 20 File: 78yt8fgkje .... 
2 12/22/2004 File: 3Bsdffsdf85  .... 
3 12/17/2004 File: 5Osdfdsf58384  .... 
4 Some May File: 0w98ejcj   .... 
5 10/24/2001 File: 2Ddsfsdfd1429  .... 
      .................... 

我需要刪除那張的File:字後在一切Attribute變量

我怎麼能做到這一點?


我從互聯網上試過這個解決方案。它不工作,我不明白什麼是32767

data newDataSet; 
set oldDataSet; 
regex1 = prxparse("/ File:.*? /"); 
call prxchange(rx1, 32767, Attribute); 
run; 
+1

標準RegExp(^。*?文件:) - ^表示文本的開始,。*?是一個非貪婪的查找任何字符零次或多次,文件:只是你想要的字符串的末尾。 –

+0

謝謝你的回覆。我想擺脫'文件.......'部分並留下任何前面的內容。你能糾正我的編碼嗎?謝謝 –

+1

32767是進行更改的次數。它顯示沒有很好地閱讀文檔的人,因爲-1會匹配所有人。 – Joe

回答

1

PRX可能是矯枉過正這一點。

data want; 
set have; 
filepos = find(attribute,'File:'); 
if filepos>0 then attribute=substr(Attribute,1,filepos+5); 
run; 

Filepos + 5會像在「之後」所說的那樣保留「File:」。如果你想擺脫「文件:」,只需擺脫+5。

+0

它運行但不會改變任何東西......它創建一個包含所有'0'值的新變量'filepos' –

+0

立即嘗試 - 我想我將參數換成了'find'。 – Joe

+0

現在它的作品謝謝你! –