BookmarkSubscribeRSS Feed
sachin01663
Obsidian | Level 7

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

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

KachiM
Rhodochrosite | Level 12

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

  • );
  • SAS Innovate 2025: Call for Content

    Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

    Submit your idea!

    How to Concatenate Values

    Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

    Find more tutorials on the SAS Users YouTube channel.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

    Discussion stats
    • 2 replies
    • 626 views
    • 0 likes
    • 3 in conversation