<?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: count all values in the field and create new var in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/count-all-values-in-the-field-and-create-new-var/m-p/330024#M9691</link>
    <description>&lt;P&gt;Use an array and loop over the array count how many members equal minus one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array x var1-var4 ;
  want=0;
  do i=1 to dim(x);
    want + (x(i)=-1);
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you changed your coding and replaced -1 with missing value (or one of the 27 special missing values) then you could use NMISS() function. &amp;nbsp;Plus you could use other functions like MIN(),MAX(), MEAN() on the set of variables since they would ignore the missing values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input var1-var4 ;
cards;
 . 20  4  .
60  .  .  .
;

data want;
  set have ;
  want = nmiss(of var1-var4);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Feb 2017 12:52:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-02-05T12:52:53Z</dc:date>
    <item>
      <title>count all values in the field and create new var</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/count-all-values-in-the-field-and-create-new-var/m-p/330012#M9689</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Have&amp;nbsp;&lt;/P&gt;&lt;P&gt;data;&lt;/P&gt;&lt;P&gt;var1 var2 var3 var4&lt;/P&gt;&lt;P&gt;-1 &amp;nbsp; &amp;nbsp; 20 &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp;-1&lt;/P&gt;&lt;P&gt;60 &amp;nbsp; -1 &amp;nbsp; &amp;nbsp; -1 &amp;nbsp; &amp;nbsp; &amp;nbsp;-1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want;&lt;/P&gt;&lt;P&gt;var1 var2 var3 var4 &amp;nbsp; want&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (counts number of vars with -1)&lt;/P&gt;&lt;P&gt;-1 &amp;nbsp; &amp;nbsp; 20 &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp;-1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;60 &amp;nbsp; -1 &amp;nbsp; &amp;nbsp; -1 &amp;nbsp; &amp;nbsp; &amp;nbsp;-1; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some vars with -1 value, I want to count how many vars have -1 values. Any ideas?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2017 06:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/count-all-values-in-the-field-and-create-new-var/m-p/330012#M9689</guid>
      <dc:creator>AZIQ1</dc:creator>
      <dc:date>2017-02-05T06:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: count all values in the field and create new var</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/count-all-values-in-the-field-and-create-new-var/m-p/330018#M9690</link>
      <description>&lt;P&gt;Use array processing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array vars {*} _numeric_;
count = 0;
do i = 1 to dim(vars);
  if vars{i} = -1 then count + 1;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Feb 2017 07:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/count-all-values-in-the-field-and-create-new-var/m-p/330018#M9690</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-05T07:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: count all values in the field and create new var</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/count-all-values-in-the-field-and-create-new-var/m-p/330024#M9691</link>
      <description>&lt;P&gt;Use an array and loop over the array count how many members equal minus one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array x var1-var4 ;
  want=0;
  do i=1 to dim(x);
    want + (x(i)=-1);
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you changed your coding and replaced -1 with missing value (or one of the 27 special missing values) then you could use NMISS() function. &amp;nbsp;Plus you could use other functions like MIN(),MAX(), MEAN() on the set of variables since they would ignore the missing values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input var1-var4 ;
cards;
 . 20  4  .
60  .  .  .
;

data want;
  set have ;
  want = nmiss(of var1-var4);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2017 12:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/count-all-values-in-the-field-and-create-new-var/m-p/330024#M9691</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-02-05T12:52:53Z</dc:date>
    </item>
  </channel>
</rss>

