Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sas Check if array/list contains element

Tags:

sas

My problem is the following.

I have a list of elements

("first element", "segundo elemento", "hirugarrena", "fourth element")

And lets say I have a separate element that says "h"

I have tried to find a way to check if there is any of the elements in the list contain that lonely element (h), so that the contains turns to be true

Something like if (list contains (h)) THEN output possible_element;

I have tried to do some silly combinations with =* and in but all I get is a sintax error.

In sum, I have been trying to find something like if/where element sounds like in list.

Can you help me?

Thanks in advance.

like image 753
fasaas Avatar asked May 29 '26 20:05

fasaas


1 Answers

If your elements are in an array, then you can use the in operator, for example:

data _null_;

  array elements(*) $20 e1-e4
      ('first element','segundo elemento','hirugarrena','fourth element');

  h = 'fourth element';

  if h in elements then do; /* USE THE IN OPERATOR TO TEST FOR A MATCH */
    put 'found';
  end;
  else do;
    put 'not found';
  end;

run;

Edit: Sorry -- I typed "if" instead of "in" in my explanation. Unfortunate typo, now corrected.

like image 135
Jeff Avatar answered Jun 01 '26 20:06

Jeff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!