<?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 check each row to see which word it contains from list of words? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578396#M164033</link>
    <description>&lt;P&gt;&amp;nbsp;How long is the list - how many words ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a very short list you can use an array like in next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
        array lst 'white' 'black' 'yellow' ...;

       flag='absent';
       do i=1 to dim(lst);
            if index(&amp;lt;col_name&amp;gt;, lst(i) then flag='exist';
       end;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For a long list you can use next code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format lib=work
   value $list
      'white' = 'exist'
      'black' = 'exist'
      'yellow' = 'exist'
     otherwise = 'absent'
; run;

data want;
 set have;
       flag = put(&amp;lt;col_name&amp;gt; , $list.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if you have the list in a dataset you can create the format from it by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntl;
  set list;
       retain fmtname '$list';
       start = &amp;lt;col_list&amp;gt;;
       end = start;
       type = 'C';   /* or maybe CHAR */
run;

proc format lib=work cntlin=cntl &amp;lt;noprint&amp;gt;;
run;

/***
  next step as before, see above 
***/
       &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;More complicate method is using hash method, which I'm not expert with it.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Aug 2019 13:36:35 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2019-08-01T13:36:35Z</dc:date>
    <item>
      <title>How to check each row to see which word it contains from list of words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578385#M164029</link>
      <description>&lt;P&gt;Using: SAS Studio 3.8, SAS 9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to check one column of each row of a dataset to see if it contains any words from a specified list. There will only be one match, and if there is no match then I want the entry to be indicated as missing. What I want to do is create a new column in the largedataset that will have the word that was matched to.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input data:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;list.csv: dog, cat, cow&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;largedataset.csv:&amp;nbsp;&lt;/P&gt;&lt;P&gt;col1 col2 colToCheck&lt;/P&gt;&lt;P&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp; &amp;nbsp;abcd/dog/123&lt;/P&gt;&lt;P&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp; &amp;nbsp;zxy123cat&lt;/P&gt;&lt;P&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp;&amp;nbsp; /123cowab&lt;/P&gt;&lt;P&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp; &amp;nbsp;abcdog&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output data:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;largedataset&lt;/P&gt;&lt;P&gt;col1 col2 colToCheck&amp;nbsp; &amp;nbsp; &amp;nbsp; newCol&lt;/P&gt;&lt;P&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp; &amp;nbsp;abcd/dog/123&amp;nbsp; &amp;nbsp;dog&lt;/P&gt;&lt;P&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp; &amp;nbsp;zxy123cat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cat&lt;/P&gt;&lt;P&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp;&amp;nbsp; /123cowab&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cow&lt;/P&gt;&lt;P&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp; &amp;nbsp;abcdog&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dog&lt;/P&gt;&lt;P&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&amp;nbsp; &amp;nbsp; &amp;nbsp;abcdefg&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to SAS and having trouble locating what I need through documentation and other forum answers.However, the "DO OVER" proc seems promising, but also seems to be unsupported?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data newdata;
	set largedata;
		do over list;
		if find (colToCheck, list, 'i') then
			newCol=list;
		else   /*else there is no match*/
			newCol=.;
		end;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 13:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578385#M164029</guid>
      <dc:creator>chcody</dc:creator>
      <dc:date>2019-08-01T13:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to check each row to see which word it contains from list of words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578396#M164033</link>
      <description>&lt;P&gt;&amp;nbsp;How long is the list - how many words ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a very short list you can use an array like in next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
        array lst 'white' 'black' 'yellow' ...;

       flag='absent';
       do i=1 to dim(lst);
            if index(&amp;lt;col_name&amp;gt;, lst(i) then flag='exist';
       end;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For a long list you can use next code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format lib=work
   value $list
      'white' = 'exist'
      'black' = 'exist'
      'yellow' = 'exist'
     otherwise = 'absent'
; run;

data want;
 set have;
       flag = put(&amp;lt;col_name&amp;gt; , $list.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if you have the list in a dataset you can create the format from it by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntl;
  set list;
       retain fmtname '$list';
       start = &amp;lt;col_list&amp;gt;;
       end = start;
       type = 'C';   /* or maybe CHAR */
run;

proc format lib=work cntlin=cntl &amp;lt;noprint&amp;gt;;
run;

/***
  next step as before, see above 
***/
       &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;More complicate method is using hash method, which I'm not expert with it.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 13:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578396#M164033</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-08-01T13:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to check each row to see which word it contains from list of words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578420#M164046</link>
      <description>&lt;P&gt;The list contains 70+ words and could become larger over time. The main issue is that&amp;nbsp;I need to be able to identify which word was matched to.&amp;nbsp; E.g. if the observation is 'abcdogdef' then the new column should contain 'dog' (instead of 'exist').&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578420#M164046</guid>
      <dc:creator>chcody</dc:creator>
      <dc:date>2019-08-01T14:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to check each row to see which word it contains from list of words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578429#M164054</link>
      <description>&lt;P&gt;As the word may be a part of a string the format method will not be applicable;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The best way will be to use the hash method.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578429#M164054</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-08-01T14:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to check each row to see which word it contains from list of words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578681#M164168</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data list;
input key $;
cards;
dog 
cat 
cow
;

data have;
input col1 $ col2 $ Check : $20.;
cards;
x       x     abcd/dog/123
x       x     zxy123cat
x       x     /123cowab
x       x     abcdog
;

proc sql;
select *
 from have as a left join list as b
  on Check contains strip(key);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Aug 2019 12:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-each-row-to-see-which-word-it-contains-from-list-of/m-p/578681#M164168</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-08-02T12:40:24Z</dc:date>
    </item>
  </channel>
</rss>

