SAS 帮助:使用索引函数比较 2 列

SAS Help: Using Index function to compare 2 columns

我想用索引函数比较A和B的字符串值。我想检查 A 的列中是否包含 B。我知道该怎么做的唯一方法是索引,但问题是索引不允许在其参数中使用列名。您必须输入一个字符串值。

试过这个:index(Address, HouseNumber)>0 但它不起作用。

示例:

Address        HouseNumber    
123 Road       Road

所以我想看看 Address 列是否在其字段中包含门牌号值。它不会是直接匹配,而只是想检查 A 是否包含该字符串。我认为使用宏变量或数组是解决方案,但我不知道该怎么做。

您需要考虑 SAS 所做的填充,因为所有变量都是固定长度的。

data have ;
  length Address HouseNumber ;
  infile cards dsd dlm='|';
  input address housenumber ;
cards;
123 Road|Road
;;;;

data want ;
  set have ;
  if index(address,strip(HouseNumber));
run;

这行得通 - 这就是您想要做的吗??

data _null_;
  a = '52 Festive Rd';
  b = 'Festive';
  if index(a,b) then put 'yes';
  else put 'no';
run;