<?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: Hash Object: How to count all non-missing and missing observations? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/551050#M8901</link>
    <description>&lt;P&gt;Why do you want to do it ? Hash is not right way to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data _null_;


set sashelp.heart end=last;
array _xchar{*} _character_;
array _xnum{*} _numeric_;

if _n_=1 then do;
 length _var_name $ 40;
 declare hash h();
 h.definekey('_var_name');
 h.definedata('_var_name','_n','_n_miss');
 h.definedone();
end;


do i=1 to dim(_xchar);
  _var_name=vname(_xchar{i});
  rc=h.find();
  if rc=0 then do;
   if missing(_xchar{i}) then  _n_miss=_n_miss+1;
   else  _n=_n+1;
   h.replace();
  end;
  else do;
   if missing(_xchar{i}) then  do;_n_miss=1;_n=0;end;
   else do;_n_miss=0;_n=1; end;
   h.replace();
  end;
end;



do i=1 to dim(_xnum);
  _var_name=vname(_xnum{i});
  rc=h.find();
  if rc=0 then do;
   if missing(_xnum{i}) then  _n_miss=_n_miss+1;
   else  _n=_n+1;
   h.replace();
  end;
  else do;
   if missing(_xnum{i}) then  do;_n_miss=1;_n=0;end;
   else do;_n_miss=0;_n=1; end;
   h.replace();
  end;
end;


if last then h.output(dataset:'want');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 15 Apr 2019 13:55:35 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-04-15T13:55:35Z</dc:date>
    <item>
      <title>Hash Object: How to count all non-missing and missing observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550884#M8866</link>
      <description>&lt;P&gt;Hi SAS community,&lt;/P&gt;&lt;P&gt;I'm working with a Hash object and I need help in figuring out how to return a count of total missing and non-missing values for all observations.&amp;nbsp; Here is the code I'm using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set &amp;amp;dataset end=last;&lt;BR /&gt;array _xchar{*} _character_;&lt;BR /&gt;array _xnum{*} _numeric_;&lt;/P&gt;&lt;P&gt;if _n_ = 1 then do;&lt;BR /&gt;*call missing(min_val, max_val);&lt;BR /&gt;length&lt;BR /&gt;_colName $ 32&lt;BR /&gt;_nMiss 8&lt;BR /&gt;_n 8&lt;BR /&gt;_type $9;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;declare hash hmiss( ordered: "Y");&lt;BR /&gt;hmiss.defineKey("_colName");&lt;BR /&gt;hmiss.defineData("_colName", "_n", "_nMiss", "_Type", "min_val", "max_val");&lt;BR /&gt;hmiss.defineDone();&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(_xchar);&lt;BR /&gt;_nMiss=0;&lt;BR /&gt;_n=0;&lt;BR /&gt;_colName = vname(_xchar{i});&lt;BR /&gt;_rc = hmiss.find();&lt;BR /&gt;_nMiss + missing(_xchar{i}) = 1;&lt;BR /&gt;_n + missing(_xchar{i}) = 0;&lt;BR /&gt;_Type = vtype(_xchar{i});&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if _Type = "C" then _Type = "Character";&lt;/P&gt;&lt;P&gt;if _rc = 0 then do;&lt;BR /&gt;if _xchar{i} &amp;lt; min_val then do;&lt;BR /&gt;min_val = _xchar{i};&lt;BR /&gt;hmiss.replace();&lt;BR /&gt;if _xchar{i} = "" then count+1;&lt;BR /&gt;end;&lt;BR /&gt;if _xchar{i} &amp;gt; max_val then do;&lt;BR /&gt;max_val = _xchar{i};&lt;BR /&gt;hmiss.replace();&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;else do;&lt;BR /&gt;min_val = _xchar{i};&lt;BR /&gt;max_val = _xchar{i};&lt;BR /&gt;hmiss.add();&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(_xnum);&lt;BR /&gt;_nMiss=0;&lt;BR /&gt;_n=0;&lt;BR /&gt;_colName = vname(_xnum{i});&lt;BR /&gt;_rc = hmiss.find();&lt;BR /&gt;_nMiss + missing(_xnum{i}) = 1;&lt;BR /&gt;_n + _xnum{i} = 0;&lt;BR /&gt;_Type = vtype(_xnum{i});&lt;BR /&gt;/*_min_colName = min(of _xnum{i});&lt;BR /&gt;_max_colName = max(of _xnum{i});*/&lt;/P&gt;&lt;P&gt;if _Type = "N" then _Type = "Numeric";&lt;/P&gt;&lt;P&gt;if _rc = 0 then do;&lt;BR /&gt;if _xnum{i} &amp;lt; min_val then do;&lt;BR /&gt;min_val = _xnum{i};&lt;BR /&gt;hmiss.replace();&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if _xnum{i} &amp;gt; max_val then do;&lt;BR /&gt;max_val = _xnum{i};&lt;BR /&gt;hmiss.replace();&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;min_val = _xnum{i};&lt;BR /&gt;max_val = _xnum{i};&lt;BR /&gt;hmiss.add();&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if last = 1 then do;&lt;BR /&gt;hmiss.output(dataset: "hashmiss");&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=hashmiss /*(drop=_n _nmiss )*/;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;Here are my results below.&amp;nbsp; I'm able to get the min value and max value of all variables by using character and numeric arrays.&amp;nbsp; However, total observations for the &amp;amp;dataset = 16467.&amp;nbsp; I would like for the sum of&amp;nbsp; _n and _nMiss to total 16467.&amp;nbsp; So for example,&amp;nbsp; INPUT_VALUE&amp;nbsp; will have _n = 16467 and _nMiss = 0, or if BIL_NUMBER has missing values then _n = 16400 and _nMiss = 67 for example.&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Obs _colName _n _nMiss _type min_val max_val &lt;TABLE cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;INPUT_VALUE&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;Character&lt;/TD&gt;&lt;TD&gt;Not found in bls&lt;/TD&gt;&lt;TD&gt;Spans bLS &amp;amp; SP&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;DSINPUT_VALUE&lt;/TD&gt;&lt;TD&gt;82&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;Character&lt;/TD&gt;&lt;TD&gt;048127326133&lt;/TD&gt;&lt;TD&gt;458128770333&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;BIL_NUMBER&lt;/TD&gt;&lt;TD&gt;115&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Character&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;7600017342&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;MBIL_NUMBER&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;Character&lt;/TD&gt;&lt;TD&g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TD&gt;11&lt;/TD&gt;&lt;TD&gt;USER_09_&lt;/TD&gt;&lt;TD&gt;13157&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Character&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2884715555556&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;USER_35_&lt;/TD&gt;&lt;TD&gt;191&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Character&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;03000048228549312&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2019 14:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550884#M8866</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2019-04-14T14:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Object: How to count all non-missing and missing observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550891#M8867</link>
      <description>&lt;P&gt;Can you post the data you are using? Or post the expected result if the following modified version of sashlelp.class is processed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.class;
    set sashelp.class;
    
    if _n_ in (1,3,7,11,17) then Age = .;
    if _n_ in (2, 3, 8, 12) then Sex = ' ';
    if _n_ in (2, 7, 15, 18) then Weight =.;
    if _n_ in (3, 11, 15, 16) then Height =.;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Apr 2019 16:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550891#M8867</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-04-14T16:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Object: How to count all non-missing and missing observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550901#M8868</link>
      <description>&lt;P&gt;This is sort of like using a sledgehammer to kill a fly.&amp;nbsp; For numerics, SAS does all this for you:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data=have n nmiss min max;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This type of report has been asked for a few times, so you will find it addressed on these message boards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are your reporting requirements rigid or will the simple approaches be just fine?&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2019 16:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550901#M8868</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-14T16:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Object: How to count all non-missing and missing observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550911#M8869</link>
      <description>&lt;P&gt;While I admire the intellectual challenge of your approach,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;'s solution is way better if other SAS users need to understand or maintain what you have done.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2019 20:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550911#M8869</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-04-14T20:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Object: How to count all non-missing and missing observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550913#M8870</link>
      <description>Thanks - unfortunately proc means does not generate the results I need for&lt;BR /&gt;character variables. Is there a simple way to do this with proc freq? I'd&lt;BR /&gt;like to have min max _n _nMiss for all variables if possible with a simple&lt;BR /&gt;procedure. If not, I'd like the community to offer their suggestions or&lt;BR /&gt;ideas!&lt;BR /&gt;</description>
      <pubDate>Sun, 14 Apr 2019 20:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550913#M8870</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2019-04-14T20:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Object: How to count all non-missing and missing observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550949#M8874</link>
      <description>&lt;P&gt;You can handle character variables separately, by creating a format.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $missfmt ' '='Missing' other='NonMissing';
run;
proc freq data=have;
tables _character_ / missing;
format _character_ $missfmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is truly a quick-and-dirty report.&amp;nbsp; But there are various ODS options that can reformat the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, there is not much point that I see in computing a minimum and maximum for a character variable.&amp;nbsp; Especially when your character variables contain digits, note that "9" is greater than "100" as a character string.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 02:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/550949#M8874</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-15T02:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Object: How to count all non-missing and missing observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/551050#M8901</link>
      <description>&lt;P&gt;Why do you want to do it ? Hash is not right way to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data _null_;


set sashelp.heart end=last;
array _xchar{*} _character_;
array _xnum{*} _numeric_;

if _n_=1 then do;
 length _var_name $ 40;
 declare hash h();
 h.definekey('_var_name');
 h.definedata('_var_name','_n','_n_miss');
 h.definedone();
end;


do i=1 to dim(_xchar);
  _var_name=vname(_xchar{i});
  rc=h.find();
  if rc=0 then do;
   if missing(_xchar{i}) then  _n_miss=_n_miss+1;
   else  _n=_n+1;
   h.replace();
  end;
  else do;
   if missing(_xchar{i}) then  do;_n_miss=1;_n=0;end;
   else do;_n_miss=0;_n=1; end;
   h.replace();
  end;
end;



do i=1 to dim(_xnum);
  _var_name=vname(_xnum{i});
  rc=h.find();
  if rc=0 then do;
   if missing(_xnum{i}) then  _n_miss=_n_miss+1;
   else  _n=_n+1;
   h.replace();
  end;
  else do;
   if missing(_xnum{i}) then  do;_n_miss=1;_n=0;end;
   else do;_n_miss=0;_n=1; end;
   h.replace();
  end;
end;


if last then h.output(dataset:'want');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 13:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/551050#M8901</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-15T13:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Object: How to count all non-missing and missing observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/551074#M8911</link>
      <description>&lt;P&gt;Ah yes, thanks!&amp;nbsp; Sometimes help from others will produce a "lightbulb" effect....&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 14:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-Object-How-to-count-all-non-missing-and-missing/m-p/551074#M8911</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2019-04-15T14:57:34Z</dc:date>
    </item>
  </channel>
</rss>

