<?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 replacement for &amp;quot;contains&amp;quot; operator for a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563564#M158004</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do have a code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table t1 (id int, name char(30));
insert into t1 
values (1, 'Peter')
values (2, 'Piper')
values (3, 'picked')
values (4, 'a peck)
values (5, 'of pickled')
values (6, 'peppers')
;
quit; 

proc sql;
create table t2 as select * from t1
where (t1.name contains 'Pet') OR (t1.name contains 'pic');
quit;&lt;/PRE&gt;&lt;P&gt;If I put the text that which I want to search in sourse in a separate dataset like&lt;/P&gt;&lt;PRE&gt;data inf;
length text $3; /*all values have the same length, this &lt;SPAN&gt;restriction&lt;/SPAN&gt; is correct*/
input text;
datalines;
Pet
pic
;
run;&lt;/PRE&gt;&lt;P&gt;what will be the most &lt;SPAN&gt;appropriate way to find it&lt;/SPAN&gt;&amp;nbsp;in the t1 table?&lt;/P&gt;&lt;P&gt;(I want to get table equal t2 using inf.text)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've found this way:&amp;nbsp;(also using find(,,))&lt;/P&gt;&lt;PRE&gt;proc sql;
create table t2 as
select * from t1
where exists (select * from inf where index(t1.name, inf.text)&amp;lt;&amp;gt;0);
quit;&lt;/PRE&gt;&lt;P&gt;But I can't say - does it work in the right way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems that this code is rather slow in my queries and I cannot understand - is there something wrong with it?&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jun 2019 16:47:22 GMT</pubDate>
    <dc:creator>Ivan555</dc:creator>
    <dc:date>2019-06-04T16:47:22Z</dc:date>
    <item>
      <title>replacement for "contains" operator for a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563564#M158004</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do have a code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table t1 (id int, name char(30));
insert into t1 
values (1, 'Peter')
values (2, 'Piper')
values (3, 'picked')
values (4, 'a peck)
values (5, 'of pickled')
values (6, 'peppers')
;
quit; 

proc sql;
create table t2 as select * from t1
where (t1.name contains 'Pet') OR (t1.name contains 'pic');
quit;&lt;/PRE&gt;&lt;P&gt;If I put the text that which I want to search in sourse in a separate dataset like&lt;/P&gt;&lt;PRE&gt;data inf;
length text $3; /*all values have the same length, this &lt;SPAN&gt;restriction&lt;/SPAN&gt; is correct*/
input text;
datalines;
Pet
pic
;
run;&lt;/PRE&gt;&lt;P&gt;what will be the most &lt;SPAN&gt;appropriate way to find it&lt;/SPAN&gt;&amp;nbsp;in the t1 table?&lt;/P&gt;&lt;P&gt;(I want to get table equal t2 using inf.text)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've found this way:&amp;nbsp;(also using find(,,))&lt;/P&gt;&lt;PRE&gt;proc sql;
create table t2 as
select * from t1
where exists (select * from inf where index(t1.name, inf.text)&amp;lt;&amp;gt;0);
quit;&lt;/PRE&gt;&lt;P&gt;But I can't say - does it work in the right way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems that this code is rather slow in my queries and I cannot understand - is there something wrong with it?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 16:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563564#M158004</guid>
      <dc:creator>Ivan555</dc:creator>
      <dc:date>2019-06-04T16:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: replacement for "contains" operator for a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563573#M158009</link>
      <description>&lt;P&gt;I've found also one more choise:&lt;/P&gt;&lt;PRE&gt;proc sql;
create table t2 as
select * from t1;
inner join inf on t1.name like '%'||inf.text||'%';
quit;&lt;/PRE&gt;&lt;P&gt;still can't choose which one is preferred..&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 17:41:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563573#M158009</guid>
      <dc:creator>Ivan555</dc:creator>
      <dc:date>2019-06-04T17:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: replacement for "contains" operator for a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563575#M158011</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272354"&gt;@Ivan555&lt;/a&gt; this code below is slower because of he enter selection process&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table t2 as
select * from t1
where exists (select * from inf where index(t1.name, inf.text)&amp;lt;&amp;gt;0);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the manner of using a data step or a SQL statement can be mainly based on preformance, user needs and controll, and sometimes using a data step is easier to explain to management whom may have no clue how code works but are required to signoff on the process.&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, 04 Jun 2019 17:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563575#M158011</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-06-04T17:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: replacement for "contains" operator for a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563605#M158025</link>
      <description>&lt;P&gt;What are the relative sizes of the actual tables involved.&amp;nbsp; Are they all SAS datasets?&amp;nbsp; Or are some in external database?&amp;nbsp; If so are both tables in the same external database?&amp;nbsp; Can you push the query into the database using explicit pass thru SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you want to do an INNER JOIN which should be pretty fast.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure the include DISTINCT keyword to avoid replicating observations with multiple "hits".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table t2 as 
  select distinct t1.* 
  from t1
  inner join INF 
    on t1.name contains inf.text
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If values of INF.TEXT are not always exactly three characters long then you might need to worry about the trailing spaces that SAS will add.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 20:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563605#M158025</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-04T20:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: replacement for "contains" operator for a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563760#M158080</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122002"&gt;@VDD&lt;/a&gt;&amp;nbsp;thank you much, understood&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; approximate size of t1-table is close to 10 mio rows, t2-table is a few dozens rows&lt;/P&gt;&lt;P&gt;&amp;gt; both tables are sas datasets&lt;/P&gt;&lt;P&gt;&amp;gt; about "distinct" - I agree, understood&lt;/P&gt;&lt;P&gt;&amp;gt; about&amp;nbsp;&amp;nbsp;"characters long" - I agree, understood&lt;/P&gt;&lt;P&gt;&amp;gt; about "&lt;SPAN&gt;the query into the database using explicit&amp;nbsp;&lt;/SPAN&gt;" I think I can't.&amp;nbsp;Due to the fact that I am representing the side of the business, I can't see databases. Maybe in future I'll be able to ask our IT-division, but in moment the only people which I can ask for help with my code are here - that is the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;your code seems works better than mine, thank you&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 16:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replacement-for-quot-contains-quot-operator-for-a-dataset/m-p/563760#M158080</guid>
      <dc:creator>Ivan555</dc:creator>
      <dc:date>2019-06-05T16:51:12Z</dc:date>
    </item>
  </channel>
</rss>

