<?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 number of times variables changes from 0 to 1 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275596#M55121</link>
    <description>&lt;P&gt;As an alternative:&lt;/P&gt;
&lt;PRE&gt;data want;
  doc1=0; doc2=1; doc3=1; doc4=0; doc5=1;
  test=count(cats(of doc:),"01");
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Jun 2016 08:53:32 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-06-07T08:53:32Z</dc:date>
    <item>
      <title>Count number of times variables changes from 0 to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275513#M55089</link>
      <description>&lt;P&gt;I have a dataset of 25000 records with this layout;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp; DOC25&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DOC26&amp;nbsp;&amp;nbsp; DOC27&amp;nbsp;&amp;nbsp; &amp;nbsp;DOC28&amp;nbsp;&amp;nbsp; DOC29&amp;nbsp;&amp;nbsp;&amp;nbsp;........ &amp;nbsp;DOC48&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DOC25-DOC48 are montly counts which have 0 if the person was on the streets, 1 if incarcerated&lt;/P&gt;
&lt;P&gt;DOC25 corresponds to January 2013&lt;/P&gt;
&lt;P&gt;DOC48 corresponds to December 2014&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to count how many times was a person incarcerated but if the person remains in prison longer than 1 month, the following months will be 1 as well until it changes to 0 when release, here in December 2014. So I want to keep track only of the first time the value changes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 20:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275513#M55089</guid>
      <dc:creator>malena</dc:creator>
      <dc:date>2016-06-06T20:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of times variables changes from 0 to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275521#M55092</link>
      <description>&lt;P&gt;The logic is if the variable value doesn't equal the previous value. You've had previous answers that demonstrate a loop over the values&lt;/P&gt;
&lt;P&gt;and declaring an array so this should be enough to get started.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If doc(i) ne doc(i-1) then flag_count+1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2016 20:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275521#M55092</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-06T20:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of times variables changes from 0 to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275526#M55094</link>
      <description>&lt;P&gt;Sounds like this should do it within a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array docs {*} doc25-doc48;&lt;/P&gt;
&lt;P&gt;incarcerated=0;&lt;/P&gt;
&lt;P&gt;do i=2 to 24;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if docs{i}=1 and docs{i-1}=0 then incarcerated + 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that if DOC25=1 then you don't want to count it as an incarceration.&amp;nbsp; If that's wrong, it's easy enough to change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 21:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275526#M55094</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-06T21:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of times variables changes from 0 to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275529#M55095</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that if DOC25=1 then you don't want to count it as an incarceration.&amp;nbsp; If that's wrong, it's easy enough to change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The alternative would require changing&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;incarcerated=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;incarcerated=docs{1};&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 21:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275529#M55095</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-06T21:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of times variables changes from 0 to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275596#M55121</link>
      <description>&lt;P&gt;As an alternative:&lt;/P&gt;
&lt;PRE&gt;data want;
  doc1=0; doc2=1; doc3=1; doc4=0; doc5=1;
  test=count(cats(of doc:),"01");
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jun 2016 08:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275596#M55121</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-07T08:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of times variables changes from 0 to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275686#M55148</link>
      <description>&lt;P&gt;Or again, if you want to count initial incarcerations&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  doc1=0; doc2=1; doc3=1; doc4=0; doc5=1;
  test=count(cats("0", of doc:),"01");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jun 2016 14:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-times-variables-changes-from-0-to-1/m-p/275686#M55148</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-07T14:44:26Z</dc:date>
    </item>
  </channel>
</rss>

