你好,
我有一列是示例描述,並且在我想從所有行中刪除的描述之前總是有一個〜數字。 只有一排有“~”。 例如。
樣本:
126:說明AB
291:說明 XYZ
~619: 描述
是否有 JSL 腳本可以從 Sample 列中的所有行中刪除“~”、前 3 位數字和“:”(包括空格)? 我正在查看的數據前面總是有一個 3 位數字以及 : 和空格。 問題是從其中一行中刪除 ~ 。
感謝幫助
喬什
這是一種方法,本質上是使用“:”作為分隔符,從最後一個“單詞”中刪除前導空格。 還有其他方法,包括正則表達式。
/*JMP STATISTICAL DISCOVERY LLC (“JMP”) PERMITS THE USE OF THIS COMPUTER SOFTWARE CODE (“CODE”) ON AN AS-IS BASIS AND AUTHORIZES YOU TO USE THE CODE SUBJECT TO THE TERMS LISTED HEREIN. BY USING THE CODE, YOU AGREE TO THESE TERMS. YOUR USE OF THE CODE IS AT YOUR OWN RISK. JMP MAKES NO REPRESENTATION OR WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRIGEMENT, AND TITLE, WITH RESPECT TO THE CODE.
You may use the Code solely as part of a software product you currently have licensed from JMP, JMP’s parent company SAS Institute Inc. (“SAS”), or one of JMP’s or SAS’s subsidiaries or authorized agents (the “Software”), and not for any other purpose. The Code is designed to add functionality to the Software but has not necessarily been tested. Accordingly, JMP makes no representation or warranty that the Code will operate error-free. JMP is under no obligation to maintain, support, or continue to distribute the Code.
Neither JMP nor its licensors shall be liable to you or any third-party for any general, special, direct, indirect, consequential, incidental, or other damages whatsoever arising out of or related to your use or inability to use the Code, even if JMP has been advised of the possibility of such damages. Except as otherwise provided above, the Code is governed by the same agreement that governs the Software. If you do not have an existing agreement with JMP or SAS governing the Software, you may not use the Code.
JMP and all other JMP Statistical Discovery LLC product or service names are registered trademarks or trademarks of JMP Statistical Discovery LLC in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies.
*/
Names Default To Here (1);
//make data table
dt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "Sample",
Character,
"Nominal",
Set Values(
{"126: Description AB", "291: Description XYZ", "~619: Description"}
)
)
);
//remove unwanted characters
for each row (dt,
:Sample = trim (word (-1, :Sample, ":"))
);你好@火腿,
由於您想要保留的部分始終與字符串的其餘部分由空格分隔,因此您可以使用如下所示的重新編碼公式來保留所有“單詞”,除了第一個(這是字符和數字的混合但不以空格分隔)。 您可以簡單地將“Column 1”列名稱更改為包含樣本描述的列名稱。
Recode(
:Column 1,
{Word(
[2 -1],
_rcNow,
Get Whitespace Characters() ||
Get Punctuation Characters( Exclude Chars( "'-" ) ),
Unmatched( _rcNow )
)}
)
希望這個其他選項對您有所幫助,
有很多不同的方法可以做到這一點,下面是一個使用正則表達式的選項
Regex("126: Description AB", "~?\d{3}: (.+)$", "\1");
Regex("291: Description XYZ", "~?\d{3}: (.+)$", "\1");
Regex("~619: Description", "~?\d{3}: (.+)$", "\1");
https://regex101.com/r/nMilGt/1稍微解釋一下正則表達式
