<?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: Is missing function fails to return nobs missing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406613#M279347</link>
    <description>&lt;P&gt;I have run your code and it seems that&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;where &amp;amp;&amp;amp;var&amp;amp;i. IS MISSING;&lt;/PRE&gt;
&lt;P&gt;does not work properly with sas sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have replaced the sql step with next step and it worked perfectly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;&amp;amp;var&amp;amp;i.;
 set tmp end=eof;
     name = compress("&amp;amp;&amp;amp;var&amp;amp;i.");
     where &amp;amp;&amp;amp;var&amp;amp;i. is missing;
     if eof then do;
        nobs_missing = _N_;
        output;
     end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 23 Oct 2017 16:14:25 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-10-23T16:14:25Z</dc:date>
    <item>
      <title>Is missing function fails to return nobs missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406554#M279345</link>
      <description>&lt;P&gt;Hi I am trying to figure out why the resulting table (final table) contains zero counts of variables that are defined to be missing (empty). Here below is the example of my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data sample;
do i = 1 to 1000;
output;
end;
run;

data tmp;
set sample;
a = .;
b = '';
c = 'text';
run;

proc contents
	data=tmp Position noprint
	out=see (keep =	LIBNAME
							MEMNAME
							NAME
							TYPE
							LENGTH
							ENGINE
							MEMTYPE
							NOBS);
run;

data _null_;
set see (keep=name);
n = _N_;
call symput('nrows',compress(n));
run;

proc sql noprint;
select distinct name
into: var1 - : var&amp;amp;nrows
from SEE;
quit;

data final_table;
LENGTH NAME $50.;
NAME = '';
NOBS_MISSING = .;
run;

data final_table;
set final_table (obs=0);
run;

%macro loop_();
%do i = 1 %to &amp;amp;nrows;

proc sql;
create table &amp;amp;&amp;amp;var&amp;amp;i. as
select
compress("&amp;amp;&amp;amp;var&amp;amp;i.") as NAME,
count(&amp;amp;&amp;amp;var&amp;amp;i.) as NOBS_MISSING
from TMP
where &amp;amp;&amp;amp;var&amp;amp;i. IS MISSING;
quit;

data final_table;
set final_table &amp;amp;&amp;amp;var&amp;amp;i.;
run;

%end;
%mend;
%loop_()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I thought it should return nobs_missing = 1000 for missing variables, i.e. "a" and "b" (no matter if char or int format). Any suggestions? Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406554#M279345</guid>
      <dc:creator>Uknown_user</dc:creator>
      <dc:date>2017-10-23T14:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Is missing function fails to return nobs missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406605#M279346</link>
      <description>&lt;P&gt;What is the question exactly?&lt;/P&gt;
&lt;P&gt;I suspect that you are getting impacted by using the WHERE clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table &amp;amp;&amp;amp;var&amp;amp;i. as
  select compress("&amp;amp;&amp;amp;var&amp;amp;i.") as NAME
       , count(&amp;amp;&amp;amp;var&amp;amp;i.) as NOBS_MISSING
  from TMP
  where &amp;amp;&amp;amp;var&amp;amp;i. IS MISSING
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If no data meets the WHERE condition then there is nothing to return so you end up with zero rows instead of one row with a count of zero.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try using MISSING() function, or a CASE statement that generates 1 or 0 values, so that you can use the SUM() aggregate function instead of COUNT()+WHERE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table &amp;amp;&amp;amp;var&amp;amp;i. as
  select compress("&amp;amp;&amp;amp;var&amp;amp;i.") as NAME
       , sum(missing(&amp;amp;&amp;amp;var&amp;amp;i.)) as NOBS_MISSING
  from TMP
  group by 1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also COUNT(X) will not count missing values of X. So if you only give it missing values you will always get a count of zero. You should use count(*) or count(1).&amp;nbsp; Run this example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select count(*) as count_of_records
     , count(age) as count_of_age
     , count(' ') as count_of_missing
from sashelp.class
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Oct 2017 21:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406605#M279346</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-23T21:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Is missing function fails to return nobs missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406613#M279347</link>
      <description>&lt;P&gt;I have run your code and it seems that&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;where &amp;amp;&amp;amp;var&amp;amp;i. IS MISSING;&lt;/PRE&gt;
&lt;P&gt;does not work properly with sas sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have replaced the sql step with next step and it worked perfectly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;&amp;amp;var&amp;amp;i.;
 set tmp end=eof;
     name = compress("&amp;amp;&amp;amp;var&amp;amp;i.");
     where &amp;amp;&amp;amp;var&amp;amp;i. is missing;
     if eof then do;
        nobs_missing = _N_;
        output;
     end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Oct 2017 16:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406613#M279347</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-10-23T16:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Is missing function fails to return nobs missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406745#M279348</link>
      <description>&lt;P&gt;Thank you both for your answers. I used proc freq which provides one with counts of missing/complete observations but wanted to know the reason for that missing function is not working properly with combination with where statement.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 21:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406745#M279348</guid>
      <dc:creator>Uknown_user</dc:creator>
      <dc:date>2017-10-23T21:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Is missing function fails to return nobs missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406748#M279349</link>
      <description>&lt;P&gt;Can you please provide a simple example of just a few data records and queries that demonstrate a case that shows either the MISSING() function or the IS MISSING logical condition not working properly?&amp;nbsp; Eliminate the macro code and macro variables, just show the data step and/or SQL query that is not producing the expected results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 21:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406748#M279349</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-23T21:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Is missing function fails to return nobs missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406752#M279350</link>
      <description>&lt;P&gt;It has been written by other user:&lt;/P&gt;&lt;PRE&gt;where &amp;amp;&amp;amp;var&amp;amp;i. IS MISSING;&lt;/PRE&gt;&lt;P&gt;Perhaps, &amp;amp;&amp;amp;var&amp;amp;i cannot be read properly and thus one needs to rewrite the form of macro variable.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 21:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406752#M279350</guid>
      <dc:creator>Uknown_user</dc:creator>
      <dc:date>2017-10-23T21:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Is missing function fails to return nobs missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406777#M279351</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; - next simplified code shows that "where var is missing" doesn't work properly in sas sql&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp1;
infile datalines dlm=',' dsd truncover;
input i char1 $ char2 $ num1 num2;
datalines;
1,x,,11,.
2,y,a,12,3
; run;

proc sql;
  create table tst_num2a as select 
  compress("num2") as NAME, 
  count(num2) as NOBS_MISSING 
  from TMP1 where (num2 IS  MISSING);
quit;

proc sql;
  create table tst_char2 as select 
  compress("char2") as NAME, 
  count(char2) as NOBS_MISSING 
  from TMP1 where (char2 IS  MISSING);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Oct 2017 00:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-missing-function-fails-to-return-nobs-missing/m-p/406777#M279351</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-10-24T00:18:26Z</dc:date>
    </item>
  </channel>
</rss>

