Paula
Paula

Reputation: 3

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.

Upvotes: 0

Views: 961

Answers (2)

Tom
Tom

Reputation: 51621

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;

Upvotes: 3

Angus
Angus

Reputation: 167

This works - is it what you're trying to do??

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

Upvotes: 0

Related Questions