<?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 How to find strings that contain values from other variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728769#M226749</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm a newbie to SAS I have 2 datasets, and I want to accomplish as below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input Description $80.;&lt;BR /&gt;cards;&lt;BR /&gt;Orange Test - Orange, All Ages - Capital&lt;BR /&gt;Test Apple ABC - &amp;lt;20, Male - Capital&lt;BR /&gt;Test Pear ABC - &amp;lt;20, Male - Capital&lt;BR /&gt;Test Apple - 21+ Years, Female - Capital&lt;BR /&gt;Pear Eligible Test - Pear Eligible, All Ages - Region&lt;BR /&gt;Pear Test - Pear Eligible, All Ages - Region&lt;BR /&gt;Other SBH - Other, All Ages - South Central&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;input key1 $ key2 $;&lt;BR /&gt;cards;&lt;BR /&gt;CAPITAL APPLE&lt;BR /&gt;CAPITAL PEAR&lt;BR /&gt;CAPITAL OTHER&lt;BR /&gt;CAPITAL ORANGE&lt;BR /&gt;REGION SSI&lt;BR /&gt;REGION PEAR&lt;BR /&gt;SOUTH OTHER&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output should look like this. List out all descriptions that contain&amp;nbsp; both key1 and key2 values :&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;key1&lt;/TD&gt;&lt;TD&gt;key2&lt;/TD&gt;&lt;TD&gt;Descr&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;APPLE&lt;/TD&gt;&lt;TD&gt;Test Apple ABC - &amp;lt;20, Male - Capital&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;APPLE&lt;/TD&gt;&lt;TD&gt;Test Apple - 21+ Years, Female - Capital&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;PEAR&lt;/TD&gt;&lt;TD&gt;Test Pear ABC - &amp;lt;20, Male - Capital&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;OTHER&lt;/TD&gt;&lt;TD&gt;not found&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;ORANGE&lt;/TD&gt;&lt;TD&gt;Orange Test - Orange, All Ages - Capital&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;REGION&lt;/TD&gt;&lt;TD&gt;SSI&lt;/TD&gt;&lt;TD&gt;not found&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;REGION&lt;/TD&gt;&lt;TD&gt;PEAR&lt;/TD&gt;&lt;TD&gt;Pear Eligible Test - Pear Eligible, All Ages - Region&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;REGION&lt;/TD&gt;&lt;TD&gt;PEAR&lt;/TD&gt;&lt;TD&gt;Pear Test - Pear Eligible, All Ages - Region&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;SOUTH&lt;/TD&gt;&lt;TD&gt;OTHER&lt;/TD&gt;&lt;TD&gt;Other SBH - Other, All Ages - South Central&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried &lt;STRONG&gt;findw&amp;nbsp;&lt;/STRONG&gt; "if&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;findw(one.Description,two.key1)&amp;gt;0 and findw(one.Description,two.key2)&amp;gt;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;then Descr=one.&lt;SPAN style="font-family: inherit;"&gt;Description&lt;/SPAN&gt;&amp;nbsp;else&amp;nbsp;Descr= 'not found' ", but it does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really appreciate your help. Thank you in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 24 Mar 2021 15:12:53 GMT</pubDate>
    <dc:creator>eduong58</dc:creator>
    <dc:date>2021-03-24T15:12:53Z</dc:date>
    <item>
      <title>How to find strings that contain values from other variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728769#M226749</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm a newbie to SAS I have 2 datasets, and I want to accomplish as below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input Description $80.;&lt;BR /&gt;cards;&lt;BR /&gt;Orange Test - Orange, All Ages - Capital&lt;BR /&gt;Test Apple ABC - &amp;lt;20, Male - Capital&lt;BR /&gt;Test Pear ABC - &amp;lt;20, Male - Capital&lt;BR /&gt;Test Apple - 21+ Years, Female - Capital&lt;BR /&gt;Pear Eligible Test - Pear Eligible, All Ages - Region&lt;BR /&gt;Pear Test - Pear Eligible, All Ages - Region&lt;BR /&gt;Other SBH - Other, All Ages - South Central&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;input key1 $ key2 $;&lt;BR /&gt;cards;&lt;BR /&gt;CAPITAL APPLE&lt;BR /&gt;CAPITAL PEAR&lt;BR /&gt;CAPITAL OTHER&lt;BR /&gt;CAPITAL ORANGE&lt;BR /&gt;REGION SSI&lt;BR /&gt;REGION PEAR&lt;BR /&gt;SOUTH OTHER&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output should look like this. List out all descriptions that contain&amp;nbsp; both key1 and key2 values :&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;key1&lt;/TD&gt;&lt;TD&gt;key2&lt;/TD&gt;&lt;TD&gt;Descr&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;APPLE&lt;/TD&gt;&lt;TD&gt;Test Apple ABC - &amp;lt;20, Male - Capital&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;APPLE&lt;/TD&gt;&lt;TD&gt;Test Apple - 21+ Years, Female - Capital&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;PEAR&lt;/TD&gt;&lt;TD&gt;Test Pear ABC - &amp;lt;20, Male - Capital&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;OTHER&lt;/TD&gt;&lt;TD&gt;not found&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAPITAL&lt;/TD&gt;&lt;TD&gt;ORANGE&lt;/TD&gt;&lt;TD&gt;Orange Test - Orange, All Ages - Capital&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;REGION&lt;/TD&gt;&lt;TD&gt;SSI&lt;/TD&gt;&lt;TD&gt;not found&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;REGION&lt;/TD&gt;&lt;TD&gt;PEAR&lt;/TD&gt;&lt;TD&gt;Pear Eligible Test - Pear Eligible, All Ages - Region&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;REGION&lt;/TD&gt;&lt;TD&gt;PEAR&lt;/TD&gt;&lt;TD&gt;Pear Test - Pear Eligible, All Ages - Region&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;SOUTH&lt;/TD&gt;&lt;TD&gt;OTHER&lt;/TD&gt;&lt;TD&gt;Other SBH - Other, All Ages - South Central&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried &lt;STRONG&gt;findw&amp;nbsp;&lt;/STRONG&gt; "if&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;findw(one.Description,two.key1)&amp;gt;0 and findw(one.Description,two.key2)&amp;gt;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;then Descr=one.&lt;SPAN style="font-family: inherit;"&gt;Description&lt;/SPAN&gt;&amp;nbsp;else&amp;nbsp;Descr= 'not found' ", but it does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really appreciate your help. Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 15:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728769#M226749</guid>
      <dc:creator>eduong58</dc:creator>
      <dc:date>2021-03-24T15:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to find strings that contain values from other variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728792#M226756</link>
      <description>&lt;P&gt;Pay attention to the MODIFIER options that the functions has.&amp;nbsp; There is a case-insensitive mode for the funciton.&amp;nbsp;&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p16rdsa30vmm43n1ej4936nwa01t.htm&amp;amp;locale=en"&gt;SAS Help Center: FINDW Function&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 15:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728792#M226756</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-03-24T15:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to find strings that contain values from other variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728793#M226757</link>
      <description>&lt;P&gt;Is this supposed to always be a case insensitive comparison? You show "APPLE" matching "Apple" as an example of insensitive.&lt;/P&gt;
&lt;P&gt;Are compound words supposed to match? "apple" and "applesauce" for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since FINDW is likely one of the proper tools then you need go through the steps below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 15:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728793#M226757</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-24T15:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to find strings that contain values from other variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728800#M226759</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/375349"&gt;@eduong58&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would use PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select t.*, coalesce(description,'not found') as Descr
from two t left join one
on findw(upcase(description),trim(key1))
 &amp;amp; findw(upcase(description),trim(key2))
order by key1, key2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This doesn't maintain the sort order of the input datasets, though. If you need this, create DATA step views with (temporary) sort keys from datasets ONE and TWO, use the views in the FROM clause and the sort keys in the ORDER BY clause:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _one / view=_one;
set one;
_seqno1=_n_;
run;

data _two / view=_two;
set two;
_seqno2=_n_;
run;

proc sql;
create table want as
select key1, key2, coalesce(description,'not found') as Descr
from _two left join _one
on findw(upcase(description),trim(key1))
 &amp;amp; findw(upcase(description),trim(key2))
order by _seqno2, _seqno1;
drop view _one, _two;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Mar 2021 16:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728800#M226759</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-24T16:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to find strings that contain values from other variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728805#M226763</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can imagine less greedy solutions exist but this should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
 if 0 then set one nobs=count;
 call symput('numobs',strip(put(count,8.)));
 STOP;
run;
%PUT&amp;amp;=numobs;

data three;
 set two;
 do pointer=1 to &amp;amp;numobs.;
  set one point=pointer;
  if     find(Description,key1,'it')^=0
     AND find(Description,key2,'it')^=0
   then output;
 end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 16:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728805#M226763</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-03-24T16:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to find strings that contain values from other variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728810#M226766</link>
      <description>&lt;P&gt;Sorry, you still have to build upon the above program to include the lines with Description='&lt;SPAN&gt;not found'.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I hadn't read the 'assignment' thoroughly&amp;nbsp;enough.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Koen&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 16:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728810#M226766</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-03-24T16:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to find strings that contain values from other variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728821#M226772</link>
      <description>Thank you so much for all of your help! I found out the issue is case insensitive. I changed that to all uppercase like @FreelanceReinhard and it works perfect!</description>
      <pubDate>Wed, 24 Mar 2021 16:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-strings-that-contain-values-from-other-variables/m-p/728821#M226772</guid>
      <dc:creator>eduong58</dc:creator>
      <dc:date>2021-03-24T16:35:34Z</dc:date>
    </item>
  </channel>
</rss>

