[英]In SAS, how to compare characters in one string separated by '/'
I'm new to SAS. 我是SAS新手。 Here is my problem. 这是我的问题。 Suppose I have the following dataset named data : 假设我有以下名为data的数据集:
id string 1 Comm Bank/Comm Bank 2 Comm Bank/Cash Flow 3 Financial Statement/Financial Statement/Financial Statement 4 Comm Bank/Wealth Management/Real Estate 5 Comm Bank/Cash Flow/Comm Bank
And I wish to create a flag followed by the rules: If all characters separated by /
are the same, then flag = 0 otherwise flag = 1. For example, the obs 1 has characters Comm Bank
and Comm Bank
and they are the same, then flag = 0
. 我希望创建一个遵循规则的标志:如果用/
分隔的所有字符都相同,则标志= 0否则标志=1。例如,obs 1具有字符Comm Bank
和Comm Bank
,它们是相同的,然后flag = 0
。 But for the obs 5, since there is a different Cash Flow
, so the flag = 1
. 但是对于obs 5,由于存在不同的Cash Flow
,所以flag = 1
。
Thank you very much! 非常感谢你!
You should just be able to compare the first word to each of the others. 您应该只能够将第一个单词与其他单词进行比较。 You can stop when you find that one does not match. 当发现一个不匹配时,您可以停止。
data want;
set have ;
flag=0
word1 = scan(string,1,'/');
do i=2 to countw(string,'/') while (flag=0);
if word1 ne scan(string,i,'/') then flag=1;
end;
run;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.