Search code examples
arrayssearchsasfuzzy-comparison

SAS Help: Using Index function to compare 2 columns


I want to compare string value of A and B by using the index function. I want to check if A contains B in its column. The only way I know how to do it is Index but the problem is index doesn't allow column name in its parameters. You have to enter a string value.

Tried this: index(Address, HouseNumber)>0 but it doesn't work.

Example:

Address        HouseNumber    
123 Road       Road

So I want to see if Address column contains House number value in its field. It wont be a direct match but just want to check if A contains the string. I think using a macro variable or array is the solution but I do not know how to do it.


Solution

  • You need to account for the padding that SAS does since all variables are fixed length.

    data have ;
      length Address HouseNumber $50;
      infile cards dsd dlm='|';
      input address housenumber ;
    cards;
    123 Road|Road
    ;;;;
    
    data want ;
      set have ;
      if index(address,strip(HouseNumber));
    run;