Reputation: 692
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.
Upvotes: 3
Views: 8401
Reputation: 80
From what I can gather I think that you may want the following:
For i = LBound(elements) To HBound(elements)
If Find(elements{i},"h") > 0 Then
do;
/*do stuff*/
End;
Next;
You can use the find function which would give you the character count of your search criteria and then just apply it to some logic.
In the above example you just need to replace 'h' with your search criteria.
Upvotes: 2
Reputation: 1807
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.
Upvotes: 3