<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to find if a variable is in an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10578#M857</link>
    <description>You can treat them as WORDS using INDEXW.&lt;BR /&gt;
&lt;BR /&gt;
Or you can use WHICHN function as in this example.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
1612  %let id_list1=%str(1 23 2 3);&lt;BR /&gt;
1613  %let id_list2=%str(1 2 3 4);&lt;BR /&gt;
1614&lt;BR /&gt;
1615  data _null_;&lt;BR /&gt;
1616     array _a[%sysfunc(countw(&amp;amp;id_list1))] (&amp;amp;id_list1);&lt;BR /&gt;
1617     array _b[%sysfunc(countw(&amp;amp;id_list2))] (&amp;amp;id_list2);&lt;BR /&gt;
1618     do i = 1 to dim(_a);&lt;BR /&gt;
1619        f = whichN(_a&lt;I&gt;,of _b&lt;/I&gt;&lt;LI&gt;&lt;I&gt;);&lt;BR /&gt;
1620        if f eq 0 then put 'NOTE: The value ' _a&lt;I&gt; 'from id_list1 is not in id_list2.';&lt;BR /&gt;
1621        end;&lt;BR /&gt;
1622     run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The value 23 from id_list1 is not in id_list2.&lt;BR /&gt;
[/pre]

Message was edited by: data _null_;&lt;/I&gt;&lt;/I&gt;&lt;/LI&gt;</description>
    <pubDate>Fri, 01 Oct 2010 19:05:21 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2010-10-01T19:05:21Z</dc:date>
    <item>
      <title>how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10570#M849</link>
      <description>here is what I want to do: &lt;BR /&gt;
I have a list of numbers stored in a macro variable, I want to find out if this list of numbers in the macro variables are all the ids or a subset of ids in a dataset. &lt;BR /&gt;
&lt;BR /&gt;
I saw there is a vinarray function in sas help but the example is not well documented, I do not understand how it would work.&lt;BR /&gt;
&lt;BR /&gt;
of course, I could use scan to get a id at a time and then to look it up in the dataset but I think there got be a easier way. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
any suggestion? thank you very much in advance.</description>
      <pubDate>Fri, 01 Oct 2010 15:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10570#M849</guid>
      <dc:creator>kwu</dc:creator>
      <dc:date>2010-10-01T15:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10571#M850</link>
      <description>can you send an example.</description>
      <pubDate>Fri, 01 Oct 2010 16:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10571#M850</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-10-01T16:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10572#M851</link>
      <description>For me, it's unclear if you are concerned about SAS variables or SAS variable "values"?  I see a reasonable example in the SAS 9.2 DOC on VINARRAY function - here:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000245979.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000245979.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
vinarray site:sas.com</description>
      <pubDate>Fri, 01 Oct 2010 17:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10572#M851</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-01T17:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10573#M852</link>
      <description>for example, &lt;BR /&gt;
&lt;BR /&gt;
%let id_list1=%str(1 23 2 3);&lt;BR /&gt;
%let id_list2=%(str(1 2 3 4);&lt;BR /&gt;
I wonder if there is an efficient way to determine that 23 is not in id_list2 .</description>
      <pubDate>Fri, 01 Oct 2010 17:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10573#M852</guid>
      <dc:creator>kwu</dc:creator>
      <dc:date>2010-10-01T17:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10574#M853</link>
      <description>thank you for the example. then vinarray would not meet my need since it checks if the variable is in the arrray. I want to check if the value is in the array.</description>
      <pubDate>Fri, 01 Oct 2010 17:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10574#M853</guid>
      <dc:creator>kwu</dc:creator>
      <dc:date>2010-10-01T17:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10575#M854</link>
      <description>You will need to parse each sub-field in "B" and check for its value in "A", or the opposite, as you require.  The process can done with either SAS macro language using %SCAN and %SYSFUNC(INDEX(argument1,argument2)) or with a DATA step, using the similar CALL function SCAN and INDEX(argument1,argument2).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 01 Oct 2010 18:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10575#M854</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-01T18:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10576#M855</link>
      <description>index would not work since &lt;BR /&gt;
&lt;BR /&gt;
index("1 23 3", "2") will return 3, which is not what I want.</description>
      <pubDate>Fri, 01 Oct 2010 18:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10576#M855</guid>
      <dc:creator>kwu</dc:creator>
      <dc:date>2010-10-01T18:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10577#M856</link>
      <description>I guess I can trick it by doing &lt;BR /&gt;
index ("1 23 3", "2 "); &lt;BR /&gt;
&lt;BR /&gt;
but I really wish there is some sas function out there which can look for a number rather than just chars.</description>
      <pubDate>Fri, 01 Oct 2010 18:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10577#M856</guid>
      <dc:creator>kwu</dc:creator>
      <dc:date>2010-10-01T18:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10578#M857</link>
      <description>You can treat them as WORDS using INDEXW.&lt;BR /&gt;
&lt;BR /&gt;
Or you can use WHICHN function as in this example.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
1612  %let id_list1=%str(1 23 2 3);&lt;BR /&gt;
1613  %let id_list2=%str(1 2 3 4);&lt;BR /&gt;
1614&lt;BR /&gt;
1615  data _null_;&lt;BR /&gt;
1616     array _a[%sysfunc(countw(&amp;amp;id_list1))] (&amp;amp;id_list1);&lt;BR /&gt;
1617     array _b[%sysfunc(countw(&amp;amp;id_list2))] (&amp;amp;id_list2);&lt;BR /&gt;
1618     do i = 1 to dim(_a);&lt;BR /&gt;
1619        f = whichN(_a&lt;I&gt;,of _b&lt;/I&gt;&lt;LI&gt;&lt;I&gt;);&lt;BR /&gt;
1620        if f eq 0 then put 'NOTE: The value ' _a&lt;I&gt; 'from id_list1 is not in id_list2.';&lt;BR /&gt;
1621        end;&lt;BR /&gt;
1622     run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The value 23 from id_list1 is not in id_list2.&lt;BR /&gt;
[/pre]

Message was edited by: data _null_;&lt;/I&gt;&lt;/I&gt;&lt;/LI&gt;</description>
      <pubDate>Fri, 01 Oct 2010 19:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10578#M857</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-10-01T19:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10579#M858</link>
      <description>perfect, that is what I want exactly. &lt;BR /&gt;
thank you so much, &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
have a good weekend.</description>
      <pubDate>Fri, 01 Oct 2010 20:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10579#M858</guid>
      <dc:creator>kwu</dc:creator>
      <dc:date>2010-10-01T20:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10580#M859</link>
      <description>one more question, is there way to break the do loop when I see a unmatch, since once a unmatch found, there is no need to do the rest check any more.</description>
      <pubDate>Fri, 01 Oct 2010 20:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10580#M859</guid>
      <dc:creator>kwu</dc:creator>
      <dc:date>2010-10-01T20:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10581#M860</link>
      <description>LEAVE;&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let id_list1=%str(1 23 2 3);&lt;BR /&gt;
%let id_list2=%str(1 2 3 4);&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   array _a[%sysfunc(countw(&amp;amp;id_list1))] (&amp;amp;id_list1);&lt;BR /&gt;
   array _b[%sysfunc(countw(&amp;amp;id_list2))] (&amp;amp;id_list2);&lt;BR /&gt;
   do k = 1 to dim(_a);&lt;BR /&gt;
      f = whichN(_a&lt;K&gt;,of _b&lt;LI&gt;);&lt;BR /&gt;
      if f eq 0 then do;&lt;BR /&gt;
         put 'NOTE: The value ' _a&lt;K&gt; 'from id_list1 is not in id_list2.';&lt;BR /&gt;
         leave;&lt;BR /&gt;
         end;&lt;BR /&gt;
      end;&lt;BR /&gt;
   put 'NOTE: stopped at ' K=;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;/K&gt;&lt;/LI&gt;&lt;/K&gt;</description>
      <pubDate>Fri, 01 Oct 2010 20:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10581#M860</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-10-01T20:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to find if a variable is in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10582#M861</link>
      <description>thank you, data _null_. &lt;BR /&gt;
&lt;BR /&gt;
I see correct the sample code, _a&lt;K&gt; even, &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/K&gt;</description>
      <pubDate>Fri, 01 Oct 2010 21:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-if-a-variable-is-in-an-array/m-p/10582#M861</guid>
      <dc:creator>kwu</dc:creator>
      <dc:date>2010-10-01T21:07:54Z</dc:date>
    </item>
  </channel>
</rss>

