<?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: retain if the variable contain specific word in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338482#M77080</link>
    <description>&lt;P&gt;You essentially have text variables with "words" separated by dashes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So examine&amp;nbsp;the sas findw function (&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002978282.htm" target="_self"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002978282.htm&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you understand that then google&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sas "subsetting if"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Mar 2017 15:59:58 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-03-06T15:59:58Z</dc:date>
    <item>
      <title>retain if the variable contain specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338479#M77079</link>
      <description>&lt;P&gt;I have the following variable&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id want 
1 an-ad-abc
1 ad
2 an-ad
2 anc-anb
2 anc
3 anc-anr-an
3 ab-ad
3 anb-anc 
3 anc-anb
4 anc-anb-ar
4 ar-anc-anb&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to retain those that contain anc either alone or in combination, so my first output will look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2 anc-anb
2 anc
3 anc-anr-an
3 anb-anc
3 anc-anb
4 anc-anb-ar
4 ar-anc-anb &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;next, if the same combination appeared for the same id in different order, I want to keep only one. Which mean anc-anb= anb-anc&amp;nbsp;so keep only one&lt;/P&gt;&lt;P&gt;and the same for anc-anb-ar= ar-anc-anb&amp;nbsp;&lt;/P&gt;&lt;P&gt;so my seconf output would eliminate those two&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2 anc-anb
2 anc
3 anc-anr-an
3 anb-anc
4 anc-anb-ar&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Mar 2017 15:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338479#M77079</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2017-03-06T15:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: retain if the variable contain specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338482#M77080</link>
      <description>&lt;P&gt;You essentially have text variables with "words" separated by dashes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So examine&amp;nbsp;the sas findw function (&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002978282.htm" target="_self"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002978282.htm&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you understand that then google&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sas "subsetting if"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 15:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338482#M77080</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-06T15:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: retain if the variable contain specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338486#M77081</link>
      <description>&lt;P&gt;Well, I got to this, its a bit verbose:&lt;/P&gt;
&lt;PRE&gt;data have;
  length want $200;
  input id want $;
  l=_n_;
datalines; 
id want 
1 an-ad-abc
1 ad
2 an-ad
2 anc-anb
2 anc
3 anc-anr-an
3 ab-ad
3 anb-anc 
3 anc-anb
4 anc-anb-ar
4 ar-anc-anb
;
run;
data inter;
  length wrd $100;
  set have;
  do i=1 to countw(want,"-");
    wrd=scan(want,i,"-");
    output;
  end;
run;
proc sort data=inter (keep=id l wrd);
  by id l wrd;
run;
proc transpose data=inter out=want;
  by id l;
  var wrd;
run;
data want (keep=id res);
  set want;
  length res $200;
  res=catx('-',of col:);
run;
proc sort data=want nodupkey;
  by id res;
  where index(res,"anc")&amp;gt;0;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 16:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338486#M77081</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-06T16:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: retain if the variable contain specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338489#M77083</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151" target="_self"&gt;RW9&lt;/A&gt;&amp;nbsp;for taking the time to write the code. It works fine until your last statement. The statement does not retain anything. Any suggestions?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you!!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;proc sort data=want nodupkey;
  by id res;
  where index(res,"anc")&amp;gt;0;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 16:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338489#M77083</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2017-03-06T16:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: retain if the variable contain specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338501#M77087</link>
      <description>&lt;P&gt;Explain what you mean by "doesn't retain anything." I ran&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;'s code and it creates a file called want that is exactly like the results you said you wanted, with the one exception that was incorrect in your example, namely that it leave out the last record of your example as it was already listed in the previous record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;4&lt;/SPAN&gt; anc&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;anb&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;ar
&lt;SPAN class="token number"&gt;4&lt;/SPAN&gt; ar&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;anc&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;anb &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should only be:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;4&lt;/SPAN&gt; anc&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;anb&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;ar&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;which is what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;'s code outputs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 17:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338501#M77087</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-06T17:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: retain if the variable contain specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338509#M77093</link>
      <description>&lt;P&gt;I agree with Art&amp;nbsp;and RW9.&amp;nbsp; The code looks OK.&amp;nbsp; I would make a small change to select the observations, adding a "w":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where index&lt;STRONG&gt;w&lt;/STRONG&gt;(res, "anc") &amp;gt; 0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using INDEX instead of INDEXW, you might pick up "anc" within a longer string such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dollar-franc-peso&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 17:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338509#M77093</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-06T17:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: retain if the variable contain specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338525#M77106</link>
      <description>&lt;P&gt;Thank you all! there was a mistake on my side! all worked fine thanks for the help&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 18:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-if-the-variable-contain-specific-word/m-p/338525#M77106</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2017-03-06T18:31:44Z</dc:date>
    </item>
  </channel>
</rss>

