<?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: handling missing data with ifn function in proc sql     ifn( missin(MPG_CITY), . , MPG_CITY&amp;gt;20 ) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627072#M185019</link>
    <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp; ifn(mpg_city&amp;gt;20, 1, 0, .) as HigherThan20&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are making up the function's syntax as you go, aren't you?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This isn't Excel. Read the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this do what you want?&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt; ifn( missing(MPG_CITY), . ,&amp;nbsp;MPG_CITY&amp;gt;20 )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2020 01:58:18 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-02-25T01:58:18Z</dc:date>
    <item>
      <title>handling missing data with ifn function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627056#M185011</link>
      <description>&lt;P&gt;In the below code, ifn function doesn't work as I expected. Can I assign missing (.) to HigherThan20 if mpg_city is missing?&lt;/P&gt;
&lt;P&gt;I would like to use PROC SQL for this, though I know there is a way to do so when using data step.&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;
data temp;
	set sashelp.cars;
	if mpg_city= 22 then mpg_city= .; run;

proc sql;
	create table temp
	as select a.type, a.mpg_city, ifn(mpg_city&amp;gt;20, 1, 0, .) as HigherThan20
	from temp a; quit;
proc print data= temp(obs= 20); run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2020 23:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627056#M185011</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2020-02-24T23:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: handling missing data with ifn function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627057#M185012</link>
      <description>&lt;P&gt;The problem is your logical expression results in a true/false regardless if mpg_city is missing or not. In this case it returns as false.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm unsure if this is the correct or best approach but it's the first solution that came to mind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table temp1
	as select a.type, a.mpg_city, ifn(mpg_city&amp;gt;20, 1, ifn(mpg_city is missing, ., 0, 0), .) as HigherThan20
	from temp a; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do think a CASE statement would be more appropriate here but I come from a SQL background.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 23:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627057#M185012</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2020-02-24T23:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: handling missing data with ifn function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627060#M185013</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select type, mpg_city
,case when (not missing(mpg_city)) then (mpg_city &amp;gt; 20) end as HigherThan20
from temp 
; 
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure why you want to use IFN() if you want to use SQL.&amp;nbsp; Use CASE instead.&lt;/P&gt;
&lt;P&gt;Boolean expressions return 1 when true and 0 when false. They never return a missing value. You will have to test for missing with your own code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 23:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627060#M185013</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-24T23:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: handling missing data with ifn function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627064#M185016</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279507"&gt;@braam&lt;/a&gt;&amp;nbsp; You need a CASE WHE construct and here is a traditional way of writing a CASE WHEN THEN ELSE END construct&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
	set sashelp.cars;
	if mpg_city= 22 then mpg_city= .; 
run;

proc sql;
create table temp_want as 
select a.type, a.mpg_city,case when  mpg_city&amp;gt;20 then 1 
when  .&amp;lt; mpg_city&amp;lt;=20 then 0 else . end as  HigherThan20
from temp a; 
quit;

proc print noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Feb 2020 00:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627064#M185016</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-25T00:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: handling missing data with ifn function in proc sql     ifn( missin(MPG_CITY), . , MPG_CITY&gt;20 )</title>
      <link>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627072#M185019</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp; ifn(mpg_city&amp;gt;20, 1, 0, .) as HigherThan20&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are making up the function's syntax as you go, aren't you?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This isn't Excel. Read the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this do what you want?&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt; ifn( missing(MPG_CITY), . ,&amp;nbsp;MPG_CITY&amp;gt;20 )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 01:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/handling-missing-data-with-ifn-function-in-proc-sql/m-p/627072#M185019</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-25T01:58:18Z</dc:date>
    </item>
  </channel>
</rss>

