<?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 Count Zeroes Values  That Follow Non-Zero Values in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Count-Zeroes-Values-That-Follow-Non-Zero-Values/m-p/936565#M10882</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An absolute noob here.&amp;nbsp; I want to be able to count the number of zeroes per row (in this case stores) that follows non- zero values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am unable to run the macro get the data step of my dataset, so apologies for the data sample below:&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data WORK.CLASS(label='Store Data');
   infile datalines dsd truncover;
   input Store:$8. Mon_01:comma18.6 Mon_02:comma18.6 Mon_03:comma18.6 Mon_04:comma18.6;
 datalines;
 123 373 373 374 375
 297 0 0 0 0
 1256 0.032 0.013 0 0.012
 5042 34 0 62 0
 9880 .9 .89 0 0
 ;;;;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I have tried multiplying the columns with the previous columns (Mon_01 * Mon_02, Mon_02 * Mon_03) , but somehow it does not work and I know that there is a better way to count the zeroes per store.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;Filoplume&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jul 2024 11:25:14 GMT</pubDate>
    <dc:creator>Filoplume</dc:creator>
    <dc:date>2024-07-22T11:25:14Z</dc:date>
    <item>
      <title>Count Zeroes Values  That Follow Non-Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-Zeroes-Values-That-Follow-Non-Zero-Values/m-p/936565#M10882</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An absolute noob here.&amp;nbsp; I want to be able to count the number of zeroes per row (in this case stores) that follows non- zero values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am unable to run the macro get the data step of my dataset, so apologies for the data sample below:&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data WORK.CLASS(label='Store Data');
   infile datalines dsd truncover;
   input Store:$8. Mon_01:comma18.6 Mon_02:comma18.6 Mon_03:comma18.6 Mon_04:comma18.6;
 datalines;
 123 373 373 374 375
 297 0 0 0 0
 1256 0.032 0.013 0 0.012
 5042 34 0 62 0
 9880 .9 .89 0 0
 ;;;;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I have tried multiplying the columns with the previous columns (Mon_01 * Mon_02, Mon_02 * Mon_03) , but somehow it does not work and I know that there is a better way to count the zeroes per store.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;Filoplume&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2024 11:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-Zeroes-Values-That-Follow-Non-Zero-Values/m-p/936565#M10882</guid>
      <dc:creator>Filoplume</dc:creator>
      <dc:date>2024-07-22T11:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count Zeroes Values  That Follow Non-Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-Zeroes-Values-That-Follow-Non-Zero-Values/m-p/936568#M10883</link>
      <description>&lt;P&gt;Believe it or not, there is some question as to what you are asking for here.&amp;nbsp; I'm going with the title:&amp;nbsp; zeros that follow nonzeros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   array counts {4} Mon_01 - Mon_04;
   zeros = 0;
   do n=2 to 4;
      if counts{n} = 0 and counts{n-1} ne 0 then zeros + 1;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jul 2024 11:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-Zeroes-Values-That-Follow-Non-Zero-Values/m-p/936568#M10883</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-07-22T11:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count Zeroes Values  That Follow Non-Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-Zeroes-Values-That-Follow-Non-Zero-Values/m-p/936569#M10884</link>
      <description>&lt;P&gt;Don't keep data in structure.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=class out=class_long;
by store;
var mon_:;
run;

data want;
do until (last.store);
  set class_long;
  by store;
  count = sum(count,(lag(col1) ne 0 and col1 = 0 and not first.store));
end;
keep store count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With the wide structure, use array processing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set class;
array mon {*} mon_:;
do i = 2 to dim(mon);
  count = sum(count,(mon{i-1} ne 0 and mon{i} = 0));
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jul 2024 12:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-Zeroes-Values-That-Follow-Non-Zero-Values/m-p/936569#M10884</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-07-22T12:01:28Z</dc:date>
    </item>
  </channel>
</rss>

