<?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 Counting Consecutive 0s in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-Consecutive-0s/m-p/48802#M10074</link>
    <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to tackle a problem in SAS. I have a dataset that has 1 row per ID. All of the rest of the variables are coded with a 0 or 1. What I am trying to do is flag if a member has 31 or more consecutive 0s. However, I only want to count the 0s that are in between each member’s first 1 and last 1.&lt;BR /&gt;
&lt;BR /&gt;
Example #1: ID #1234’s first 1 is the variable Mar0900 and their last 1 is the variable Apr0900. This person does not have 31+ consecutive 0s in the variables between Mar0900 and Apr0900. Flag=N&lt;BR /&gt;
&lt;BR /&gt;
Example #2: ID #2222’s first 1 is the variable Mar1000 and their last 1 is the variable Apr1500. This person has 31+ consecutive 0s in the variables between Mar1000 and Apr1500. Flag=Y&lt;BR /&gt;
&lt;BR /&gt;
Example #3: ID #9876’s first 1 is the variable Apr0900 and their last 1 is the variable Apr1400. This person does not have 31+ consecutive 0s in the variables between Apr0900 and Apr1400. They do have 31+ consecutive 0s, but they happen before their first 1, therefore they do not count. Flag=N&lt;BR /&gt;
&lt;BR /&gt;
Know of any code that I can use to do this? I would greatly appreciate any help in tackling this problem!&lt;BR /&gt;
&lt;BR /&gt;
Thank you!</description>
    <pubDate>Thu, 25 Jun 2009 16:14:31 GMT</pubDate>
    <dc:creator>kac</dc:creator>
    <dc:date>2009-06-25T16:14:31Z</dc:date>
    <item>
      <title>Counting Consecutive 0s</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Consecutive-0s/m-p/48802#M10074</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to tackle a problem in SAS. I have a dataset that has 1 row per ID. All of the rest of the variables are coded with a 0 or 1. What I am trying to do is flag if a member has 31 or more consecutive 0s. However, I only want to count the 0s that are in between each member’s first 1 and last 1.&lt;BR /&gt;
&lt;BR /&gt;
Example #1: ID #1234’s first 1 is the variable Mar0900 and their last 1 is the variable Apr0900. This person does not have 31+ consecutive 0s in the variables between Mar0900 and Apr0900. Flag=N&lt;BR /&gt;
&lt;BR /&gt;
Example #2: ID #2222’s first 1 is the variable Mar1000 and their last 1 is the variable Apr1500. This person has 31+ consecutive 0s in the variables between Mar1000 and Apr1500. Flag=Y&lt;BR /&gt;
&lt;BR /&gt;
Example #3: ID #9876’s first 1 is the variable Apr0900 and their last 1 is the variable Apr1400. This person does not have 31+ consecutive 0s in the variables between Apr0900 and Apr1400. They do have 31+ consecutive 0s, but they happen before their first 1, therefore they do not count. Flag=N&lt;BR /&gt;
&lt;BR /&gt;
Know of any code that I can use to do this? I would greatly appreciate any help in tackling this problem!&lt;BR /&gt;
&lt;BR /&gt;
Thank you!</description>
      <pubDate>Thu, 25 Jun 2009 16:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Consecutive-0s/m-p/48802#M10074</guid>
      <dc:creator>kac</dc:creator>
      <dc:date>2009-06-25T16:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Consecutive 0s</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Consecutive-0s/m-p/48803#M10075</link>
      <description>Using a DATA step, setup an ARRAY declaring your variable list for the array contents.  Using a DO/END loop and the DIM(&lt;ARRAYNAME&gt;) function, work through the array variables and detect (using a temp SAS variable) your initial condition, then start counting (within the DO/END) until you reach the end of the array variable list -- you likely do not need to pass the variable list multiple times to establish the lowest/first and highest/last "1" condition/value, but that would depend on your DO/END loop code.&lt;BR /&gt;
&lt;BR /&gt;
I suggest searching the SAS support website  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  with some focus on SAS-hosted documentation and also supplemental technical/conference papers on ARRAY processing, and use DIM as a search keyword.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/ARRAYNAME&gt;</description>
      <pubDate>Thu, 25 Jun 2009 16:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Consecutive-0s/m-p/48803#M10075</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-25T16:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Consecutive 0s</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Consecutive-0s/m-p/48804#M10076</link>
      <description>As Scott mentioned you can acheive this by using arrays and Do loop. I have tried this for count &amp;gt;=4 then flag="Y". Try the below code if it fits for your requirement.&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
 input id x1 x2 x3 x4 x5 x6 x7 x8 x9 x10;&lt;BR /&gt;
 cards;&lt;BR /&gt;
 101 1 0 0 0 0 0 1 0 0 0 &lt;BR /&gt;
 102 0 0 0 0 0 0 1 0 0 0&lt;BR /&gt;
 103 1 0 0 0 0 0 0 0 0 0&lt;BR /&gt;
 104 1 0 0 1 0 0 0 0 0 1 &lt;BR /&gt;
 105 1 0 0 1 0 0 0 0 1 0 &lt;BR /&gt;
 ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data test1;&lt;BR /&gt;
  set test;&lt;BR /&gt;
  by id notsorted;&lt;BR /&gt;
  array temp{*} x1-x10;&lt;BR /&gt;
  if first.id then do;&lt;BR /&gt;
     ss=0;&lt;BR /&gt;
	 cnt=1;&lt;BR /&gt;
  end;&lt;BR /&gt;
  do i=1 to dim(temp)-1;&lt;BR /&gt;
     if temp(i)=1 then ss=1;&lt;BR /&gt;
	 else if temp(i)=0 and ss=1 then do; &lt;BR /&gt;
	     if temp(i+1)=1 then do;&lt;BR /&gt;
             cnt=cnt;&lt;BR /&gt;
		     if cnt&amp;gt;=4 then do;&lt;BR /&gt;
                 flag="Y";&lt;BR /&gt;
				 cnt=1;&lt;BR /&gt;
			 	 ss=0;&lt;BR /&gt;
			 end;&lt;BR /&gt;
	     end;&lt;BR /&gt;
	     else if temp(i+1)=0 then cnt+1;&lt;BR /&gt;
	 end;&lt;BR /&gt;
  end;&lt;BR /&gt;
  if flag='' then flag='N';&lt;BR /&gt;
  put _all_;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
~ Sukanya E</description>
      <pubDate>Thu, 25 Jun 2009 22:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Consecutive-0s/m-p/48804#M10076</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-25T22:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Consecutive 0s</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Consecutive-0s/m-p/48805#M10077</link>
      <description>Reusing Sukanya's data, you can also check this using character functions.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data TEST;&lt;BR /&gt;
  input ID X1-X10;&lt;BR /&gt;
  STR=cats(of X1-X10);                                  * create one string;&lt;BR /&gt;
  STR1=substr(STR,1,findc(STR,'1',-99));                * remove all zeroes after last 1;&lt;BR /&gt;
  FLAG=ifc(find(STR1,'0000',findc(STR1,'1')),'Y','N');  * look for 4 zeroes after 1st 1;&lt;BR /&gt;
cards;&lt;BR /&gt;
101 1 0 0 0 0 0 1 0 0 0 &lt;BR /&gt;
102 0 0 0 0 0 0 1 0 0 0&lt;BR /&gt;
103 1 0 0 0 0 0 0 0 0 0&lt;BR /&gt;
104 1 0 0 1 0 0 0 0 0 1 &lt;BR /&gt;
105 1 0 0 1 0 0 0 0 1 0 &lt;BR /&gt;
run;</description>
      <pubDate>Fri, 26 Jun 2009 01:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Consecutive-0s/m-p/48805#M10077</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-06-26T01:02:33Z</dc:date>
    </item>
  </channel>
</rss>

