<?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: ROUND Function Returning Missing Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/435973#M108350</link>
    <description>&lt;P&gt;Not sure why that doesn't work as expected, but I think that the following does:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
    select REGION, SUM(SALES) as SALES, SUM(PROFIT) as PROFIT,
        case
          when CALCULATED SALES gt 0 and CALCULATED PROFIT gt 0
           then ROUND(calculated PROFIT / calculated SALES, 0.01)
          else 0
        end as MARGIN
      from HAVE
        group by 1
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Feb 2018 18:57:23 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2018-02-10T18:57:23Z</dc:date>
    <item>
      <title>ROUND Function Returning Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/435970#M108349</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; create table WANT as
	select REGION, SUM(SALES) as SALES, SUM(PROFIT) as PROFIT,
		   IFN(CALCULATED SALES in (0,.) or CALCULATED PROFIT in (0,.), 0, ROUND(PROFIT / SALES, 0.01)) as MARGIN
	from HAVE
	group by 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to do a calculation and I thought the code&amp;nbsp;I have would eliminate any missing values in the results since I am&amp;nbsp;checking for missing values before I do the ROUND(PROFIT / SALES, 0.01) calculation.&amp;nbsp; However,&amp;nbsp;when I go to the log, I see the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Invalid (or missing) arguments to the ROUND function have caused the function to return a missing value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have zeroes in the output and not missing values and I thought the code I have would produce that but&amp;nbsp;unfortunately it is&amp;nbsp;not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help understanding why would be appreciated.&amp;nbsp; Thanks in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 17:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/435970#M108349</guid>
      <dc:creator>GeorgeBonanza</dc:creator>
      <dc:date>2018-02-10T17:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: ROUND Function Returning Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/435973#M108350</link>
      <description>&lt;P&gt;Not sure why that doesn't work as expected, but I think that the following does:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
    select REGION, SUM(SALES) as SALES, SUM(PROFIT) as PROFIT,
        case
          when CALCULATED SALES gt 0 and CALCULATED PROFIT gt 0
           then ROUND(calculated PROFIT / calculated SALES, 0.01)
          else 0
        end as MARGIN
      from HAVE
        group by 1
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 18:57:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/435973#M108350</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-02-10T18:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: ROUND Function Returning Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/435985#M108357</link>
      <description>&lt;P&gt;I found the answer to why my code worked as expected, but yours didn't.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;"When the IFN and IFC functions are called, SAS evaluates all of the arguments, even those which end up unused." (quote from:&amp;nbsp;&lt;SPAN&gt;&lt;A href="http://www.howles.com/saspapers/CC33.pdf" target="_blank"&gt;www.howles.com/saspapers/CC33.pdf&lt;/A&gt; ).&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Since I first saw Howard's paper, I have always tried to imbed the lag function within an ifn or ifc function so that the lag functioned as expected.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;However, in your case, that precise functionality was causing the notes in your log.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Also, you had a problem in that you didn't state your ifn condition so that it had three possible results, namely true, false and missing. The following would still produce the annoying note, but at least would have worked as expected:&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;proc sql; create table WANT as
	select REGION, SUM(SALES) as SALES, SUM(PROFIT) as PROFIT,
		   IFN(CALCULATED SALES+CALCULATED PROFIT,
		     ROUND(calculated PROFIT / calculated SALES, 0.01),
		     0,
		     0) as MARGIN
	from HAVE
	group by 1;
quit;
&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Art, CEO, AnalystFinder.com&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sat, 10 Feb 2018 20:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/435985#M108357</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-02-10T20:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: ROUND Function Returning Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436007#M108372</link>
      <description>&lt;P&gt;All three IFN arguments are evaluated, irrespective of the value of the condition. The &lt;EM&gt;&lt;STRONG&gt;case when else end&lt;/STRONG&gt; &lt;/EM&gt;construct does a better job:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;select&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;REGION,&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; SUM(SALES) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; SALES, &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; SUM(PROFIT) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; PROFIT,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;case&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; CALCULATED SALES &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) or CALCULATED PROFIT &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ROUND(calculated PROFIT / calculated SALES, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0.01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;end&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; MARGIN&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; HAVE&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;group&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; region;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 22:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436007#M108372</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-02-10T22:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: ROUND Function Returning Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436015#M108377</link>
      <description>&lt;P&gt;What about COALESCE() instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ROUND(coalesce(PROFIT, 0)  / coalesce(SALES, 0), 0.01)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you still have to account for dividing by zero.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 23:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436015#M108377</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-10T23:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: ROUND Function Returning Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436016#M108378</link>
      <description>&lt;P&gt;What about COALESCE() instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ROUND(coalesce(PROFIT, 0)  / coalesce(SALES, 0), 0.01)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you still have to account for dividing by zero.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 23:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436016#M108378</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-10T23:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: ROUND Function Returning Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436019#M108379</link>
      <description>Thanks for your help!</description>
      <pubDate>Sat, 10 Feb 2018 23:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436019#M108379</guid>
      <dc:creator>GeorgeBonanza</dc:creator>
      <dc:date>2018-02-10T23:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: ROUND Function Returning Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436020#M108380</link>
      <description>Using CASE prevented the note from printing to the log. Thanks for your help!</description>
      <pubDate>Sat, 10 Feb 2018 23:11:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/436020#M108380</guid>
      <dc:creator>GeorgeBonanza</dc:creator>
      <dc:date>2018-02-10T23:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: ROUND Function Returning Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/499079#M132752</link>
      <description>&lt;P&gt;No big deal as you&amp;nbsp;can make use the DIVIDE function to properly handle the divisions by zero&amp;nbsp;&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 13:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ROUND-Function-Returning-Missing-Values/m-p/499079#M132752</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2018-09-26T13:46:21Z</dc:date>
    </item>
  </channel>
</rss>

