简体   繁体   English

在SAS中,如何比较用'/'分隔的一个字符串中的字符

[英]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 BankComm 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.

相关问题 如何计算数组中字符串值中的字符数,然后将其与其他字符进行比较以找到最长的一个? - How can I count the number of characters in a string value, within an array, and then compare it to others to find the longest one? 斯威夫特字符串比较字符 - Swift string compare characters MYSQL - 将 arrays 与逗号分隔的字符串进行比较 - MYSQL - compare arrays with comma separated string 如何将一个字符串中的字符存储到数组中? - How to store the characters from one string into an array? 如何在一行中将字符串偶数索引和奇数索引字符打印为 2 个空格分隔的字符串? - How to print string even-indexed and odd-indexed characters as 2 space-separated strings on a single line? 如何将字符串 arrays 与 java 中的一个字符串进行比较 - how to compare string arrays withe one string in java 使用 sas 将一组日期与另一组日期进行比较 - Using sas to compare one sets of dates with another sets of dates 如何正确排序一个字符串的字符以与Java中的另一个字符串进行比较? - How do I properly sort the characters of a String to compare to another String in Java? 将带有分隔空间的字符串存储到一个索引bash中 - storing a string with separated space into one index bash 如何将字符数组与布尔值进行比较 - How to compare array of characters to Boolean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM