<?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 isn't my code flagging variables correctly? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327481#M271671</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/118497"&gt;@confused_saser&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to flag one of my variables (tsi_days) only when it is less than 0. However my code seems to also be flagging my variable when it is also missing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if tsi_days &amp;lt; 0 then tsi_exclude=1;
	else if tsi_days=. then tsi_exclude=0;
	else tsi_exclude=0;&lt;/PRE&gt;
&lt;P&gt;What am I doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is the output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG title="tsi.png" alt="tsi.png" src="https://communities.sas.com/t5/image/serverpage/image-id/6883iB105CC9D14D28A98/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's because missing is less than 0.&amp;nbsp; Do the test for missing first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jan 2017 18:33:20 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2017-01-25T18:33:20Z</dc:date>
    <item>
      <title>Why isn't my code flagging variables correctly?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327464#M271669</link>
      <description>&lt;P&gt;I am trying to flag one of my variables (tsi_days) only when it is less than 0. However my code seems to also be flagging my variable when it is also missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if tsi_days &amp;lt; 0 then tsi_exclude=1;
	else if tsi_days=. then tsi_exclude=0;
	else tsi_exclude=0;&lt;/PRE&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/6883iB105CC9D14D28A98/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="tsi.png" title="tsi.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 17:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327464#M271669</guid>
      <dc:creator>confused_saser</dc:creator>
      <dc:date>2017-01-25T17:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my code flagging variables correctly?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327480#M271670</link>
      <description>&lt;P&gt;In SAS, a missing numeric value is &amp;lt; 0. Thus, you must test&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tsi_exclude = tsi_days &amp;lt; 0 and not missing(tsi_days);&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 18:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327480#M271670</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-01-25T18:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my code flagging variables correctly?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327481#M271671</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/118497"&gt;@confused_saser&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to flag one of my variables (tsi_days) only when it is less than 0. However my code seems to also be flagging my variable when it is also missing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if tsi_days &amp;lt; 0 then tsi_exclude=1;
	else if tsi_days=. then tsi_exclude=0;
	else tsi_exclude=0;&lt;/PRE&gt;
&lt;P&gt;What am I doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is the output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG title="tsi.png" alt="tsi.png" src="https://communities.sas.com/t5/image/serverpage/image-id/6883iB105CC9D14D28A98/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's because missing is less than 0.&amp;nbsp; Do the test for missing first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 18:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327481#M271671</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-01-25T18:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my code flagging variables correctly?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327482#M271672</link>
      <description>&lt;P&gt;That's because SAS flags missing values as less than negative, so your first condition is flagging them as such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way of doing your code as you wish is to use the&amp;nbsp;&lt;EM&gt;sign&lt;/EM&gt; function. This returns values of &lt;EM&gt;-1&lt;/EM&gt; for negative, &lt;EM&gt;0&lt;/EM&gt;&amp;nbsp;for zero and&amp;nbsp;&lt;EM&gt;1&lt;/EM&gt; for positive. Or you can change the order of your conditions (I use&amp;nbsp;&lt;EM&gt;select&amp;nbsp;&lt;/EM&gt;because it makes for ease of reading)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select;
   when(missing(tsi_days))
       tsi_exclude = 0;
   when(tsi_days &amp;lt; 0)
       tsi_days = 1;
   otherwise &lt;BR /&gt;       tsi_exclude = 0;
   end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jan 2017 18:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327482#M271672</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-25T18:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my code flagging variables correctly?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327483#M271673</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;what do you mean do the test for missing? I'm not sure I understand what that means&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 18:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327483#M271673</guid>
      <dc:creator>confused_saser</dc:creator>
      <dc:date>2017-01-25T18:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my code flagging variables correctly?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327542#M271674</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/118497"&gt;@confused_saser&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;what do you mean do the test for missing? I'm not sure I understand what that means&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In your code you have a test for missing&lt;/P&gt;
&lt;PRE&gt;if tsi_days &amp;lt; 0 then tsi_exclude=1;
	&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;else if tsi_days=.&lt;/STRONG&gt; &lt;/FONT&gt;then tsi_exclude=0;
	else tsi_exclude=0;&lt;/PRE&gt;
&lt;P&gt;I'm saying do that first and then do the test for TSI_DAYS &amp;lt; 0.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 21:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-code-flagging-variables-correctly/m-p/327542#M271674</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-01-25T21:18:59Z</dc:date>
    </item>
  </channel>
</rss>

