Hi everyone,
I'm trying to do a program and I get stocked when I need to search if a variable is one of the list of other variable.
I want to do something like this
Data example;
list="1,4,5";
target="3";
if target in list then put "WORKS";
run;
but it give me an error, anyone know an alternative way to do it?
Thanks in advance!
Well, first way which came to mind:
if index(list,target)>0 then "Found";
index gives you the first position of the target, or 0 if not found:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212242.htm
There is also find(), findw() etc.
Well, first way which came to mind:
if index(list,target)>0 then "Found";
index gives you the first position of the target, or 0 if not found:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212242.htm
There is also find(), findw() etc.
The only Function that come to my mind in this moment was the IN but both are right.
Thanks a lot.
The SAS IN operator currently looks in a list of specific values.
You can use:
if Find(list, target)>0 then put "WORKS";
there are modifiers to ignore case and trailing blanks which may be needed when your target is shorter than its declared length.
Also FINDC if only ever searching for single character.
The INDEX function could also do similar but is always case sensitive.
Not a LIST an ARRAY.
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: