<?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: question on substring in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/293456#M61076</link>
    <description>&lt;P&gt;Thank you all for your help. I have a follow up on this question if my table&amp;nbsp;B is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code&lt;/P&gt;
&lt;P&gt;a35,a90&lt;/P&gt;
&lt;P&gt;a36,a3540&lt;/P&gt;
&lt;P&gt;zz72&lt;/P&gt;
&lt;P&gt;a10,x1010&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;
&lt;P&gt;The output I want is the below to only pick those where the codes are available in table A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table B&lt;/P&gt;
&lt;P&gt;code &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;codenew&lt;/P&gt;
&lt;P&gt;35,90 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a35&lt;/P&gt;
&lt;P&gt;36,3540 &amp;nbsp; &amp;nbsp; &amp;nbsp;a3540&lt;/P&gt;
&lt;P&gt;72&lt;/P&gt;
&lt;P&gt;10,1010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried with find and substring but I am not getting hte answer I want.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Aug 2016 14:45:42 GMT</pubDate>
    <dc:creator>hdg</dc:creator>
    <dc:date>2016-08-23T14:45:42Z</dc:date>
    <item>
      <title>question on substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289900#M59919</link>
      <description>&lt;P&gt;I was wondering if someone could help me solve this problem maybe using sql (open to other solutions that are fast)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table A&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code&lt;/P&gt;
&lt;P&gt;35&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;20&lt;/P&gt;
&lt;P&gt;50&lt;/P&gt;
&lt;P&gt;3540&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code&lt;/P&gt;
&lt;P&gt;35,90&lt;/P&gt;
&lt;P&gt;36,3540&lt;/P&gt;
&lt;P&gt;72&lt;/P&gt;
&lt;P&gt;10,1010&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to filter codes in table B by those available in table A, only one code can be selected for each row.&lt;/P&gt;
&lt;P&gt;Table b is separated by commas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output I want is the below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table B&lt;/P&gt;
&lt;P&gt;code &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;codenew&lt;/P&gt;
&lt;P&gt;35,90 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;35&lt;/P&gt;
&lt;P&gt;36,3540 &amp;nbsp; &amp;nbsp; &amp;nbsp;3540&lt;/P&gt;
&lt;P&gt;72&lt;/P&gt;
&lt;P&gt;10,1010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much!&lt;/P&gt;
&lt;P&gt;H&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2016 22:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289900#M59919</guid>
      <dc:creator>hdg</dc:creator>
      <dc:date>2016-08-05T22:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: question on substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289909#M59927</link>
      <description>&lt;P&gt;I think a data step is better in this case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Load table A into a temporary array&lt;/P&gt;
&lt;P&gt;2. Loop through string searching all values of temporary array. &lt;U&gt;&lt;STRONG&gt;What happens if multiple matches?&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;This is a fairly similar idea, except&amp;nbsp;rather than comparing to values in the temporary array you're checking for equality and then you can create new variable as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/f052b5223fecca066b1f" target="_blank"&gt;https://gist.github.com/statgeek/f052b5223fecca066b1f&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2016 22:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289909#M59927</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-05T22:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: question on substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289915#M59932</link>
      <description>&lt;P&gt;Here is Hash approach. You can do this using array too. It is easy to get CODE instead of code_new. If you insist on this name, it is still possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input code;
datalines;
35
10
20
50
3540
;
run;

data b;
input code_s $20.;
datalines; 
35,90
36,3540
72
10,1010
;
run;

data want;
   if _n_ = 1 then do;
      if 0 then set a;
      declare hash h(dataset:'a');
      h.definekey('code');
      h.definedone();
   end;
   set b;
   nw = countw(code_s, ',');
   do i = 1 to nw;
      code = input(scan(code_s, i, ','), 8.);
      if h.find() = 0 then output;
   end;
drop i nw;
run;

proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Aug 2016 01:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289915#M59932</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-08-06T01:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: question on substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289920#M59933</link>
      <description>&lt;P&gt;A SQL solution could be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select b.code_s, a.code
from 
    b left join 
    a 
        on a.code = input(scan(b.code_s,1,","),best.) or
           a.code = input(scan(b.code_s,2,","),best.);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but join conditions involving the OR operator are notoriously inefficient in SAS/SQL. On the other hand, if you are willing to store codes as in your B table, you can't be very worried about efficiency &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2016 02:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289920#M59933</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-08-06T02:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: question on substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289925#M59934</link>
      <description>&lt;P&gt;Assuming the "codes" variables are character below could work as well&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as
    select b.code_s, a.code
    from b left join a
    on find(b.code_s,a.code,'t')&amp;gt;=1
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Aug 2016 03:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/289925#M59934</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-08-06T03:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: question on substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/293456#M61076</link>
      <description>&lt;P&gt;Thank you all for your help. I have a follow up on this question if my table&amp;nbsp;B is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code&lt;/P&gt;
&lt;P&gt;a35,a90&lt;/P&gt;
&lt;P&gt;a36,a3540&lt;/P&gt;
&lt;P&gt;zz72&lt;/P&gt;
&lt;P&gt;a10,x1010&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;
&lt;P&gt;The output I want is the below to only pick those where the codes are available in table A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table B&lt;/P&gt;
&lt;P&gt;code &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;codenew&lt;/P&gt;
&lt;P&gt;35,90 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a35&lt;/P&gt;
&lt;P&gt;36,3540 &amp;nbsp; &amp;nbsp; &amp;nbsp;a3540&lt;/P&gt;
&lt;P&gt;72&lt;/P&gt;
&lt;P&gt;10,1010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried with find and substring but I am not getting hte answer I want.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 14:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/293456#M61076</guid>
      <dc:creator>hdg</dc:creator>
      <dc:date>2016-08-23T14:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: question on substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/293499#M61090</link>
      <description>&lt;P&gt;Start a new question. Make sure to highlight how it differs and what doesn't work from current solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 17:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-on-substring/m-p/293499#M61090</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-23T17:36:13Z</dc:date>
    </item>
  </channel>
</rss>

