Any easy way to look for a value in multiple columns

Reply
Contributor
Posts: 40

Any easy way to look for a value in multiple columns

Hi,

I have around 80 columns (Col1 to Col80). These columns have city names. I need to look through all columns and see if there in city 'London'.

I have done this by Concatinating the column values and looking for string 'London' but I am hoping there must be an easier way.

The other alternative I was thinking was arrays but I don't want to create another 80 variables or change the values of existing ones.

Thanks as always.

S

Esteemed Advisor
Esteemed Advisor
Posts: 7,190

Re: Any easy way to look for a value in multiple columns

Hi,

Well, you don't need to create new variables in the array:

data have;

  col1="New York"; col2="London"; output;

run;

data want;

  set have;

  array col{2};

  if find(cats(of col{*}),"London")>0 then Flag="Y";

run;

Super Contributor
Posts: 251

Re: Any easy way to look for a value in multiple columns

Yet other ways ..

data _null_;

     set have;

     array k _character_;

     if 'London' IN k then put 'Found';

run;

You can use:

whichC('London', of k

  • );
  • Ask a Question
    Discussion stats
    • 2 replies
    • 147 views
    • 0 likes
    • 3 in conversation