<?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: Why doesn't the &amp;quot;contains &amp;quot;yes&amp;quot;&amp;quot; and select subquery produce the same result in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983087#M379462</link>
    <description>&lt;P&gt;I did a simple test with sashelp.class and got expected result.&lt;/P&gt;
&lt;P&gt;Can you post some test data (in form of a data step/datalines) so we can try your exact scenario?&lt;/P&gt;</description>
    <pubDate>Thu, 05 Feb 2026 15:46:48 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2026-02-05T15:46:48Z</dc:date>
    <item>
      <title>Why doesn't the "contains "yes"" and select subquery produce the same result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983086#M379461</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm stumped. I have two versions of a query syntax that should produce the same result but it doesn't!&lt;/P&gt;
&lt;P&gt;Ver1:&lt;/P&gt;
&lt;PRE&gt;select * from tbl where col1 contains "yes"&lt;/PRE&gt;
&lt;P&gt;Ver2:&lt;/P&gt;
&lt;PRE&gt;select * from tbl where col1 contains (select distinct test from xl.sheet1 where some_col="example")&lt;/PRE&gt;
&lt;P&gt;The subquery&amp;nbsp;&lt;STRONG&gt;(select distinct test from xl.sheet1 where some_col="example")&lt;/STRONG&gt; from Ver2 returns "yes".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that Ver1 returns exactly as expected, but Ver2 returns just a fraction of Ver1. What am I missing here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Feb 2026 15:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983086#M379461</guid>
      <dc:creator>current_thing</dc:creator>
      <dc:date>2026-02-05T15:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't the "contains "yes"" and select subquery produce the same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983087#M379462</link>
      <description>&lt;P&gt;I did a simple test with sashelp.class and got expected result.&lt;/P&gt;
&lt;P&gt;Can you post some test data (in form of a data step/datalines) so we can try your exact scenario?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Feb 2026 15:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983087#M379462</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2026-02-05T15:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't the "contains "yes"" and select subquery produce the same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983088#M379463</link>
      <description>&lt;P&gt;The issue is trailing spaces.&amp;nbsp; If the length of TEST is $8 then it returns 'yes&amp;nbsp; &amp;nbsp; &amp;nbsp;' and not 'yes'.&amp;nbsp; So the contains will only match values of COL1 that yes followed by five spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only way I could get it to work is to add LENGTH= option to force the subquery to generate a value without trailing spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  string='A ';
run;

proc sql;
select * from sashelp.class where name contains 'A';
%put &amp;amp;=sqlobs;
select * from sashelp.class where name contains (select string from have);
%put &amp;amp;=sqlobs;
select * from sashelp.class where name contains (select string length=1 from have);
%put &amp;amp;=sqlobs;
select * from have where string contains (select string from have);
%put &amp;amp;=sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also note that the subquery must only return on value.&lt;/P&gt;
&lt;PRE&gt; 89         data have;
 90           input string $ ;
 91         cards;
 
 NOTE: The data set WORK.HAVE has 3 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 95         ;
 96         proc sql;
 97         select * from sashelp.class where name contains (select string from have);
 ERROR: Subquery evaluated to more than one row.
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 98         quit;
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Feb 2026 15:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983088#M379463</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-02-05T15:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't the "contains "yes"" and select subquery produce the same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983092#M379464</link>
      <description>&lt;P&gt;Tom, that worked! Length= in the subquery was the solution!&lt;/P&gt;</description>
      <pubDate>Thu, 05 Feb 2026 16:42:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983092#M379464</guid>
      <dc:creator>current_thing</dc:creator>
      <dc:date>2026-02-05T16:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't the "contains "yes"" and select subquery produce the same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983114#M379466</link>
      <description>&lt;P&gt;Or using STRIP() function to get rid of these heading/trailing blanks .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  string='A ';
run;

proc sql;
/*select * from sashelp.class where name contains 'A';*/
select * from sashelp.class where name contains &lt;STRONG&gt;strip(&lt;/STRONG&gt;(select string from have)&lt;STRONG&gt;)&lt;/STRONG&gt;;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Feb 2026 07:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983114#M379466</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-02-06T07:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't the "contains "yes"" and select subquery produce the same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983132#M379468</link>
      <description>&lt;P&gt;That solves the problem of the subquery generating a character variable that is longer than the string it contains.&amp;nbsp; Note that it only works in this case because CONTAINS can only except one value from the subquery.&amp;nbsp; So there is no conflict with the fact that the STRIP() function can only operate on one value at a time.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Feb 2026 15:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-quot-contains-quot-yes-quot-quot-and-select/m-p/983132#M379468</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-02-06T15:36:10Z</dc:date>
    </item>
  </channel>
</rss>

