<?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: Start indexing based on given value. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Start-indexing-based-on-given-value/m-p/822206#M324656</link>
    <description>I appreciate your help.&lt;BR /&gt;Thank you.</description>
    <pubDate>Fri, 08 Jul 2022 05:07:19 GMT</pubDate>
    <dc:creator>sascode</dc:creator>
    <dc:date>2022-07-08T05:07:19Z</dc:date>
    <item>
      <title>Start indexing based on given value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Start-indexing-based-on-given-value/m-p/822186#M324647</link>
      <description>Hello,&lt;BR /&gt;I have a binary variable for each id like this:&lt;BR /&gt;ID  Binary  wanted(index)&lt;BR /&gt;1    0            0&lt;BR /&gt;1    0            0&lt;BR /&gt;1    1            0&lt;BR /&gt;1    0            1&lt;BR /&gt;1    0            2&lt;BR /&gt;1    0            3&lt;BR /&gt;2    0            0&lt;BR /&gt;2    1            0&lt;BR /&gt;2     0           1&lt;BR /&gt;3     1           0&lt;BR /&gt;3     0           1&lt;BR /&gt;......................&lt;BR /&gt;So assuming I have only first two variables,how I can generate third wanted(index)?&lt;BR /&gt;Note:Within each id, if binary before 1 is 0 then index is 0,then,when reaches 1,index starts from 0 and assigns index counts for each 0 after 1.&lt;BR /&gt;For instance,  for ID 3 there are not 0 before 1 at binary, therefore it starts indexing directly. &lt;BR /&gt;Thanks.</description>
      <pubDate>Fri, 08 Jul 2022 01:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Start-indexing-based-on-given-value/m-p/822186#M324647</guid>
      <dc:creator>sascode</dc:creator>
      <dc:date>2022-07-08T01:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Start indexing based on given value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Start-indexing-based-on-given-value/m-p/822205#M324655</link>
      <description>&lt;P&gt;You need&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;a data step with "by Id"&lt;/LI&gt;
&lt;LI&gt;"retain" to preserve the values of "index" and a helper-variable (increase)&lt;/LI&gt;
&lt;LI&gt;reset index and increase when the a new id is read for the first time&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	by id;
	
	retain index increase;
	
	if first.id then do;
		index = 0;
		increase = 0;
	end;
	
	if binary then do;
		increase = 1;
	end;
	
	output;
	
	index = index + increase;
	
	drop increase;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Fri, 08 Jul 2022 04:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Start-indexing-based-on-given-value/m-p/822205#M324655</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-07-08T04:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: Start indexing based on given value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Start-indexing-based-on-given-value/m-p/822206#M324656</link>
      <description>I appreciate your help.&lt;BR /&gt;Thank you.</description>
      <pubDate>Fri, 08 Jul 2022 05:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Start-indexing-based-on-given-value/m-p/822206#M324656</guid>
      <dc:creator>sascode</dc:creator>
      <dc:date>2022-07-08T05:07:19Z</dc:date>
    </item>
  </channel>
</rss>

