<?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 Most efficient way to get missing and total count of CHAR vars? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-missing-and-total-count-of-CHAR-vars/m-p/346505#M79918</link>
    <description>&lt;P&gt;If I just had numeric columns I could do something like this using proc means:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data = x ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var _numeric_ ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am guessing that proc FREQ might be the best but thought I would check and see what other come up with on this board.&lt;/P&gt;</description>
    <pubDate>Sun, 02 Apr 2017 18:12:25 GMT</pubDate>
    <dc:creator>tbellmer_wf</dc:creator>
    <dc:date>2017-04-02T18:12:25Z</dc:date>
    <item>
      <title>Most efficient way to get missing and total count of CHAR vars?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-missing-and-total-count-of-CHAR-vars/m-p/346505#M79918</link>
      <description>&lt;P&gt;If I just had numeric columns I could do something like this using proc means:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data = x ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var _numeric_ ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am guessing that proc FREQ might be the best but thought I would check and see what other come up with on this board.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Apr 2017 18:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-missing-and-total-count-of-CHAR-vars/m-p/346505#M79918</guid>
      <dc:creator>tbellmer_wf</dc:creator>
      <dc:date>2017-04-02T18:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to get missing and total count of CHAR vars?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-missing-and-total-count-of-CHAR-vars/m-p/346514#M79921</link>
      <description>&lt;P&gt;The following articles provides you with your answer:&amp;nbsp;&lt;A href="http://blogs.sas.com/content/iml/2011/09/19/count-the-number-of-missing-values-for-each-variable.html" target="_blank"&gt;http://blogs.sas.com/content/iml/2011/09/19/count-the-number-of-missing-values-for-each-variable.html&lt;/A&gt;&lt;/P&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>Sun, 02 Apr 2017 19:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-missing-and-total-count-of-CHAR-vars/m-p/346514#M79921</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-02T19:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to get missing and total count of CHAR vars?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-missing-and-total-count-of-CHAR-vars/m-p/346557#M79935</link>
      <description>&lt;P&gt;Function NMISS() work for both numeric and character variable in SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
if _n_ in (1 4 7 9) then call missing (sex,age);
if _n_ in (10 12) then call missing (sex);
run;
proc sql;
select nmiss(sex) as n_missing_sex,
       nmiss(age) as n_missing_age
  from class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Apr 2017 01:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-missing-and-total-count-of-CHAR-vars/m-p/346557#M79935</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-03T01:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to get missing and total count of CHAR vars?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-missing-and-total-count-of-CHAR-vars/m-p/346559#M79936</link>
      <description>&lt;P&gt;Proc tabulate seems the fastest, and as a bonus it produces an output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  length VAR1-VAR20 $16 VAR21-VAR50 8;
  do i=1 to 1e7;
    VAR1=ifc(ranuni(0)&amp;gt;.5,' ','A');
    output; 
  end;
run;

proc format;
 value $missfmt ' '='Missing' other='Not Missing';
run;
 
proc freq data=HAVE;                        *  FREQ real time = cpu time = 9 seconds  ;
  format _CHAR_ $missfmt.; 
  tables _CHAR_ / missing ;
run;

proc means data=HAVE(keep=_CHAR_) missing;  * MEANS real time=7s CPU time=35s;
  format _CHAR_ $missfmt.; 
  class _CHAR_;
  ways 1;
  output out=MEANS;
run ;

proc iml;                                   *  IML real time = cpu time = 9 seconds  ;
  use HAVE;
  read all var _CHAR_ into x[colname=cNames]; 
  close HAVE;
  c = countn(x,"col");
  cmiss = countmiss(x,"col");
  rNames = {"    Missing", "Not Missing"};
  cnt = (cmiss // c) ;
  print cnt[r=rNames c=cNames label=""];
quit;

proc contents data=HAVE out=NAMES noprint;run;
data _null_;                                 * SQL real time = CPU time = 17s ;
  if _N_=1 then call execute('proc sql; select ');
  set NAMES(where =(TYPE=2)) end=LASTOBS;
  call execute(ifc(_N_ &amp;gt; 1, ',', ' '));
  call execute(cat('sum(missing(',NAME,')) as ',trim(NAME),'_MISS'));
  call execute(cat(',sum(^missing(',NAME,')) as ',NAME));
  if LASTOBS then call execute('from HAVE; quit;');  
run;

proc tabulate data=HAVE out=TAB missing;   * TABULATE  real time=6s CPU time=17s ;
  class _CHAR_;
  format _CHAR_ $missfmt.; 
  table _CHAR_, n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 02:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-missing-and-total-count-of-CHAR-vars/m-p/346559#M79936</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-04-03T02:23:18Z</dc:date>
    </item>
  </channel>
</rss>

