<?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: Searching multiple columns and grouping results. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Searching-multiple-columns-and-grouping-results/m-p/763331#M241739</link>
    <description>&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Use WHICHC() to see fi the term is present&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;If present, loop through and concatenate the names of the variables.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _cols (*) col1-col3;

length results $300.;
call missing(Results);

if whichc("Apple", of _cols(*)) then do i=1 to dim(_cols);
    if _cols(i) = "Apple" then results = catx(", ", results, vname(_cols(i)));
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393065"&gt;@jrevinzon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Lets say I have 100 columns with various character strings. I want to search all of the columns to see if they contain the word "Apple". I then want to create another column that creates a list of all the columns that contained the word "Apple".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Col1&amp;nbsp; &amp;nbsp; &amp;nbsp;Col2&amp;nbsp; &amp;nbsp; &amp;nbsp;Col3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Results&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apple&amp;nbsp; &amp;nbsp; Berry&amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Berry&amp;nbsp; &amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp; &amp;nbsp;Col1, Col 2&lt;/P&gt;
&lt;P&gt;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;None&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help with this would be appreciated.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Aug 2021 19:18:49 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-08-23T19:18:49Z</dc:date>
    <item>
      <title>Searching multiple columns and grouping results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-multiple-columns-and-grouping-results/m-p/763327#M241736</link>
      <description>&lt;P&gt;Lets say I have 100 columns with various character strings. I want to search all of the columns to see if they contain the word "Apple". I then want to create another column that creates a list of all the columns that contained the word "Apple".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;Col1&amp;nbsp; &amp;nbsp; &amp;nbsp;Col2&amp;nbsp; &amp;nbsp; &amp;nbsp;Col3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Results&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apple&amp;nbsp; &amp;nbsp; Berry&amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col1&amp;nbsp;&lt;/P&gt;&lt;P&gt;Berry&amp;nbsp; &amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp; &amp;nbsp;Col1, Col 2&lt;/P&gt;&lt;P&gt;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;None&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help with this would be appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 19:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-multiple-columns-and-grouping-results/m-p/763327#M241736</guid>
      <dc:creator>jrevinzon</dc:creator>
      <dc:date>2021-08-23T19:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Searching multiple columns and grouping results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-multiple-columns-and-grouping-results/m-p/763328#M241737</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393065"&gt;@jrevinzon&lt;/a&gt;&amp;nbsp; A quick clue for you. Look at WHICHC/WHICHN group of functions. I am lazy to write the code. But there are gazillion examples online. All the best!&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 19:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-multiple-columns-and-grouping-results/m-p/763328#M241737</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-08-23T19:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Searching multiple columns and grouping results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-multiple-columns-and-grouping-results/m-p/763331#M241739</link>
      <description>&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Use WHICHC() to see fi the term is present&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;If present, loop through and concatenate the names of the variables.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _cols (*) col1-col3;

length results $300.;
call missing(Results);

if whichc("Apple", of _cols(*)) then do i=1 to dim(_cols);
    if _cols(i) = "Apple" then results = catx(", ", results, vname(_cols(i)));
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393065"&gt;@jrevinzon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Lets say I have 100 columns with various character strings. I want to search all of the columns to see if they contain the word "Apple". I then want to create another column that creates a list of all the columns that contained the word "Apple".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Col1&amp;nbsp; &amp;nbsp; &amp;nbsp;Col2&amp;nbsp; &amp;nbsp; &amp;nbsp;Col3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Results&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apple&amp;nbsp; &amp;nbsp; Berry&amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Berry&amp;nbsp; &amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp; &amp;nbsp;Col1, Col 2&lt;/P&gt;
&lt;P&gt;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;None&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help with this would be appreciated.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 19:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-multiple-columns-and-grouping-results/m-p/763331#M241739</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-23T19:18:49Z</dc:date>
    </item>
  </channel>
</rss>

