<?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: Text search based on Column values in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235092#M55013</link>
    <description>&lt;P&gt;Follow&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;'s advice, join the two tables with a CONTAINS operation :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table found as
   select a.searchterm, b.comment
   from searchtermdataset as a cross join surveydataset as b
   where upcase(b.comment) contains upcase(a.searchterm);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that doesn't work, please tell us why. Stay away from macro programming, it's inefficient and not required here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Nov 2015 18:10:26 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2015-11-17T18:10:26Z</dc:date>
    <item>
      <title>Text search based on Column values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235046#M54997</link>
      <description>&lt;P&gt;I have a text field ("Comments") in survey data. &amp;nbsp;I need to search that field for values in a column in another table. &amp;nbsp;I know how to do a basic search based on a single specified value or discrete&amp;nbsp;SET of values I can easily type out individually. &amp;nbsp; However, there are too many values to type for what I want to search. &amp;nbsp;I need to search the comments field for all responses, where it contains one of the codes contained in a column. &amp;nbsp; Any help would be greatly appreciated. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 15:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235046#M54997</guid>
      <dc:creator>WGE914</dc:creator>
      <dc:date>2015-11-17T15:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Text search based on Column values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235050#M55000</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5464"&gt;@WGE914&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have a text field ("Comments") in survey data. &amp;nbsp;I need to search that field for values in a column in another table.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the values you want to search for are in another table, first you'd have to combine the table with Comments and the table with the values to search for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&amp;nbsp;I know how to do a basic search based on a single specified value or discrete&amp;nbsp;SET of values I can easily type out individually. &amp;nbsp; However, there are too many values to type for what I want to search. &amp;nbsp;I need to search the comments field for all responses, where it contains one of the codes contained in a column. &amp;nbsp; Any help would be greatly appreciated. &amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So multiple columns of values to search for. Sounds like you need an array, and then loop over all of the columns in your search. If the value of count is greater than 0, then you have found that the comment field contains at least one of these values. In this example, I have assumed there are 100 variables with the values to search for, named col1-col100, but naturally you can replace that part of the code with the exact column names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data doing_the_search;
     set combined;
     array col column1-column100;
     count=0;
     do i=1 to 100;
           if find(comments,col{i})&amp;gt;0 then count=count+1;
     end;
run;
           &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Nov 2015 15:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235050#M55000</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-11-17T15:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Text search based on Column values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235051#M55001</link>
      <description>&lt;P&gt;Either I'm reading your response incorrectly, or there's a misunderstanding. &amp;nbsp;There is only one column which has the values I want to search for. &amp;nbsp;Call this column "Code". &amp;nbsp;Each respondent filled it in, and most of them have text in the comments field. &amp;nbsp;I want to search the "Comments" field for value&amp;nbsp;in the "Code" column. &amp;nbsp; The Code column is text, but everything is the same length (5). &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 16:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235051#M55001</guid>
      <dc:creator>WGE914</dc:creator>
      <dc:date>2015-11-17T16:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Text search based on Column values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235052#M55002</link>
      <description>&lt;P&gt;Do you have the terms you want to search for in some form that you can read into a SAS data set? That would be your best bet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then probably one or more SQL merges with that search item&amp;nbsp;dataset and your surveydata would work.&lt;/P&gt;
&lt;P&gt;Something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; create table found as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; select a.searchterm, b.comment&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; from searchtermdataset as a join surveydataset as b&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where upcase(b.comment) contains upcase(a.searchterm);&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: this will only find exact matches, may miss similar terms like singular if searching for plural.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 16:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235052#M55002</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-11-17T16:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Text search based on Column values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235064#M55005</link>
      <description>&lt;P&gt;flag=find(comments,code);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If flag&amp;gt;0 then you have found the text string in code within the text string called comments.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 16:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235064#M55005</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-11-17T16:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Text search based on Column values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235078#M55009</link>
      <description>&lt;P&gt;I don't think I was clear, Iapologize. &amp;nbsp;I want to search ALL values in the "code" column, not just for the value in the corresponding row. &amp;nbsp;So, it would require some sort of loop, I know that much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other words, I need something that would work the same way as: &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select * from survey_data&lt;/P&gt;
&lt;P&gt;where comments like "%(select code from survey_data)%"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried a variation of the above statement using a macro variable within the like statement, but it only reads the first row. &amp;nbsp;I need a macro to be read as an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 17:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235078#M55009</guid>
      <dc:creator>WGE914</dc:creator>
      <dc:date>2015-11-17T17:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Text search based on Column values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235092#M55013</link>
      <description>&lt;P&gt;Follow&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;'s advice, join the two tables with a CONTAINS operation :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table found as
   select a.searchterm, b.comment
   from searchtermdataset as a cross join surveydataset as b
   where upcase(b.comment) contains upcase(a.searchterm);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that doesn't work, please tell us why. Stay away from macro programming, it's inefficient and not required here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 18:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Text-search-based-on-Column-values/m-p/235092#M55013</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-17T18:10:26Z</dc:date>
    </item>
  </channel>
</rss>

