<?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: Coding questions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824531#M325629</link>
    <description>&lt;P&gt;As you realize, for numeric variables, the missing value is considered "less than" all valid numeric values.&amp;nbsp; And the "&amp;gt;" operator (unlike arithmetic operators) will not object when one or both values are missing.&amp;nbsp; Perhaps you want something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if nmiss(oai,cai)=0 then OSA=(OAI&amp;gt; CAI);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will leave OSA as missing if either OSI or CAI is missing.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jul 2022 01:15:56 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-07-21T01:15:56Z</dc:date>
    <item>
      <title>Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824515#M325621</link>
      <description>&lt;P&gt;I am creating two variables using if, then statement.&lt;/P&gt;&lt;P&gt;In the statement OAI&amp;gt; CAI, it returns a value of 1 for the variable OSA since 18.7 is greater than the missing value. OSA should be missing not 1. How do I correct this?&lt;/P&gt;&lt;P&gt;Here is the two lines of data and the codes that I have used.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-07-20 154544.jpg" style="width: 544px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73555i62165DBFC4DAB628/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-07-20 154544.jpg" alt="Screenshot 2022-07-20 154544.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 22:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824515#M325621</guid>
      <dc:creator>fdehkord</dc:creator>
      <dc:date>2022-07-20T22:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824517#M325622</link>
      <description>&lt;P&gt;Why should OSA be anything but 1? The condition is met.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 22:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824517#M325622</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-20T22:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824519#M325624</link>
      <description>&lt;P&gt;Because CAI value for this subject is missing and we do not know what the actual value is. It could be smaller or larger.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 23:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824519#M325624</guid>
      <dc:creator>fdehkord</dc:creator>
      <dc:date>2022-07-20T23:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824520#M325625</link>
      <description>&lt;P&gt;SAS defines missing as the lowest value, if you want to ignore missing values you need to code that logic into your IF statement explicitly. Use the NOT MISSING() function or NMISS() to check multiple variables at once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if nmiss(CAI, OAI, AHI) = 0 and ...rest of your criteria&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2022 23:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824520#M325625</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-20T23:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824521#M325626</link>
      <description>&lt;P&gt;Please post code as text, preferably in a text or code box opened using the &amp;lt;/&amp;gt; or "running man" icons that appear above the message window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only want to assign values to variables with the independent variables are not missing it is your responsibility to test for that before any calculation.&lt;/P&gt;
&lt;P&gt;Missing values are less than any actual value so the condition is true.&lt;/P&gt;
&lt;P&gt;You can test a number of numeric values for missing using the NMISS function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If nmiss(AHI, CAI, OAI) &amp;gt; 0 then &amp;lt;do whatever you do when one of these is missing&amp;gt;;&lt;/P&gt;
&lt;P&gt;Else if AHI &amp;gt;= 15 ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you have multiple statements that would depend on that likely&lt;/P&gt;
&lt;PRE&gt;If nmiss(AHI, CAI, OAI) = 0 then do;
   if AHI &amp;gt;= ... OSA=0;
   if AHI &amp;gt;= ... CSA=0;
end;&lt;/PRE&gt;
&lt;P&gt;Note that SAS will return a numeric 1 for True and 0 for False for logical comparisons. So instead of an if/then/else you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; OSA = (AHI&amp;gt;=15 and OAI&amp;gt;CAI);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 00:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824521#M325626</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-21T00:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824531#M325629</link>
      <description>&lt;P&gt;As you realize, for numeric variables, the missing value is considered "less than" all valid numeric values.&amp;nbsp; And the "&amp;gt;" operator (unlike arithmetic operators) will not object when one or both values are missing.&amp;nbsp; Perhaps you want something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if nmiss(oai,cai)=0 then OSA=(OAI&amp;gt; CAI);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will leave OSA as missing if either OSI or CAI is missing.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 01:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824531#M325629</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-07-21T01:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824555#M325639</link>
      <description>&lt;P&gt;Thank you, but I still have the same problem. Here are the codes that I used and the output.&lt;/P&gt;&lt;PRE&gt;Data HFPEE;
Set myHFPEE;
If nmiss(AHI,CAI, OAI) = 0 then OSA = (AHI&amp;gt;=15 and OAI&amp;gt;CAI) ;
If nmiss(AHI,CAI, OAI) = 0 then CSA= (AHI&amp;gt;=15 and CAI&amp;gt;=OAI);
Run;&lt;/PRE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Obs&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;AHI&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;CAI&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;OAI&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;OSA&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;CSA&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;43&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;39.4&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;.&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;18.7&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;393&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;23&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2.5&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;.&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 21 Jul 2022 06:44:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824555#M325639</guid>
      <dc:creator>fdehkord</dc:creator>
      <dc:date>2022-07-21T06:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824556#M325640</link>
      <description>&lt;P&gt;Make sure that OSA and CSA are not already present in the dataset, or use an ELSE to set them to missing.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 07:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824556#M325640</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-21T07:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824698#M325694</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards;
input ahi cai oai;
cards;
39.4 . 18.7
23 2.5 .
;;;;
run;

Data HFPEE;
Set have;
If nmiss(AHI,CAI, OAI) = 0 then OSA = (AHI&amp;gt;=15 and OAI&amp;gt;CAI) ;
If nmiss(AHI,CAI, OAI) = 0 then CSA= (AHI&amp;gt;=15 and CAI&amp;gt;=OAI);
Run;

proc print data=HFPEE;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Guessing that you already have OSA/CSA in your data set then as the above works as expected and need to set them to missing before the calculation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 15:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824698#M325694</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-21T15:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: Coding questions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824703#M325696</link>
      <description>&lt;P&gt;&amp;nbsp;OSA/CSA were present in my data set from the previous runs and as soon as I remove them it worked fine. Thank you very much.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 15:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-questions/m-p/824703#M325696</guid>
      <dc:creator>fdehkord</dc:creator>
      <dc:date>2022-07-21T15:38:13Z</dc:date>
    </item>
  </channel>
</rss>

