大字符串中关键字的模糊匹配-SAS
使用SAS,我有一个包含句子的表格,我希望通过模糊匹配(大字符串中关键字的模糊匹配-SAS,sas,substring,proc-sql,fuzzy-comparison,Sas,Substring,Proc Sql,Fuzzy Comparison,使用SAS,我有一个包含句子的表格,我希望通过模糊匹配(complev function)在表格中查找关键字所在的行。SAS中有没有办法在句子中找到关键字字符串?我知道如何使用complev,但我只能使用它来比较完整的字符串,而不能将字符串作为较大字符串的一部分。对于这个示例表,关键字将是'example',比较结果将出现在result列中。 谢谢你的想法 This is an Example sentence : 1 Here is another one : 0 Also an exmple
complev function
)在表格中查找关键字所在的行。SAS中有没有办法在句子中找到关键字字符串?我知道如何使用complev
,但我只能使用它来比较完整的字符串,而不能将字符串作为较大字符串的一部分。对于这个示例表,关键字将是'example'
,比较结果将出现在result
列中。
谢谢你的想法
This is an Example sentence : 1
Here is another one : 0
Also an exmple : 1
The examples keep coming : 1
No worries : 0
看看是否可以将其用作模板。我将Complev值与3进行比较,但可以将其设置为任何拟合值
data have;
input string $ 1-25;
datalines;
Example sentence
Here is another one
Also an exmple
The examples keep coming
No worries
;
data want;
set have;
result = 0;
do _N_ = 1 to countw(string);
if complev('example', scan(string, _N_)) < 3 then do;
result=1; leave;
end;
end;
run;
数据已经存在;
输入字符串$1-25;
数据线;
例句
这是另一个
也是一个例子
例子层出不穷
别担心
;
数据需求;
集有;
结果=0;
do _N_=1到countw(字符串);
如果complev('example',scan(string,_N_))<3,则执行;
结果=1;离开
结束;
结束;
跑
编辑:如果您希望比较不区分大小写,请使用
complev('example',scan(string,_N_),'i')
。是否值得标准化大小写(大写/小写)或complev()
是否已经说明了这一点?很好,谢谢您!我想是的,但是浏览一下医生,我错了。我编辑了答案。。