<?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: proc sql finds data where there is none in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325176#M72299</link>
    <description>&lt;P&gt;Look at this progression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select age from sashelp.class;
select age from sashelp.class where 0;
select count(*), min(age) from sashelp.class where 0;
select count(*), min(age) from sashelp.class where 0 having 0;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;try to guess which queries return something.&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jan 2017 04:58:57 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-01-17T04:58:57Z</dc:date>
    <item>
      <title>proc sql finds data where there is none</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325138#M72282</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first query doesn’t find data:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;NOTE: No rows were selected. in the log&lt;/LI&gt;
&lt;LI&gt;&amp;amp;t1=&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;while the second one does, though there is no matching data in the table.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;No message in the log (when is proc sql going to mention observations processed? When?)&lt;/LI&gt;
&lt;LI&gt;&amp;amp;t2=999&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone can provide an explanation to this strange behaviour? Is it a defect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let t1= ; 
%let t2= ; 
proc sql ;
  select min(999,WEIGHT) into :t1 from SASHELP.CLASS where AGE=2;
quit;
proc sql ;
  select min(999,max(WEIGHT)) into :t2 from SASHELP.CLASS where AGE=2;
quit;
%put &amp;amp;=t1 &amp;amp;=t2;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Jan 2017 22:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325138#M72282</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-01-16T22:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql finds data where there is none</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325141#M72284</link>
      <description>&lt;P&gt;Yup. &lt;EM&gt;max(weight)&lt;/EM&gt; will always return missing (first principles). The&amp;nbsp;&lt;EM&gt;min&lt;/EM&gt; function picks that up&amp;nbsp;&lt;EM&gt;after the query&lt;/EM&gt;, and then returns the mininum value of 999 and missing (999, by definition). It's almost as if it's turning the rest into a subquery and acting on it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's something I quite often take advantage of when I don't want a macro variable to have a missing value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select coalesce(max(weight), 0)
  into :test_query
  from sashelp.class
 where age = 2;
quit;&lt;BR /&gt;
%put &amp;amp;=test_query;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS I like the debugging&amp;nbsp;&lt;EM&gt;%put &amp;amp;=varname&lt;/EM&gt; syntax. I never knew!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 22:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325141#M72284</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-16T22:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql finds data where there is none</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325145#M72285</link>
      <description>&lt;P&gt;Thanks for the quick reply!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WEIGHT wil also return missing since there is no data, just like max(WEIGHT). Why the difference?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And mostly why does the statement even execute when no row is returned?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt; It's something I quite often take advantage of when I don't want a macro variable to have a missing value&lt;/P&gt;
&lt;P&gt;coalesce() does this for you, the dark magic of returning non-existing data is not needed for this, is it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt;I like the debugging&amp;nbsp;&lt;EM&gt;%put &amp;amp;=varname&lt;/EM&gt; syntax. I never knew!&lt;/P&gt;
&lt;P&gt;Yes, very handy!&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 22:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325145#M72285</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-01-16T22:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql finds data where there is none</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325147#M72287</link>
      <description>&lt;P&gt;Oh I see what you mean. OK - I'll revise that. The implicit&amp;nbsp;&lt;EM&gt;group by&lt;/EM&gt; of a function like&amp;nbsp;&lt;EM&gt;max&lt;/EM&gt;&amp;nbsp;(where its the function activing over the whole query) acts after the primary query (the&amp;nbsp;&lt;EM&gt;from&lt;/EM&gt; and&amp;nbsp;&lt;EM&gt;where&lt;/EM&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first query is using a SAS function&amp;nbsp;&lt;EM&gt;min&lt;/EM&gt;; your second query is using an SQL&amp;nbsp;&lt;EM&gt;min&lt;/EM&gt;. They function differently.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 22:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325147#M72287</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-16T22:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql finds data where there is none</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325148#M72288</link>
      <description>&lt;P&gt;&lt;FONT color="#0000FF"&gt;min(999,WEIGHT) into :t1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt; is never evaluated because of the condition ( try it after %let t1=x; ), whereas&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;select max(WEIGHT) from SASHELP.CLASS where AGE=2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;returns a missing value, then&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;min(999,&amp;nbsp;.) into :t2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;puts 999 into t2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 23:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325148#M72288</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-01-16T23:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql finds data where there is none</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325156#M72289</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt; Thank you. I am starting to get it.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt; This almost makes sense! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Would you mind breaking the logic in a similar manner without the into clause?&lt;/P&gt;
&lt;P&gt;The second select statement generates a report while the first one doesn't. I'd like to see where "select" appears in the broken-down steps?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 00:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325156#M72289</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-01-17T00:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql finds data where there is none</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325176#M72299</link>
      <description>&lt;P&gt;Look at this progression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select age from sashelp.class;
select age from sashelp.class where 0;
select count(*), min(age) from sashelp.class where 0;
select count(*), min(age) from sashelp.class where 0 having 0;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;try to guess which queries return something.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 04:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325176#M72299</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-01-17T04:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql finds data where there is none</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325530#M72400</link>
      <description>&lt;P&gt;Thank you both.&lt;/P&gt;
&lt;P&gt;There's always something to learn isn't there?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 00:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-finds-data-where-there-is-none/m-p/325530#M72400</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-01-18T00:51:44Z</dc:date>
    </item>
  </channel>
</rss>

