<?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 a value _ Conditional loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-a-value-Conditional-loop/m-p/515672#M139190</link>
    <description>&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by order_id;&lt;/P&gt;
&lt;P&gt;if first.order_id then count_var=1;&lt;/P&gt;
&lt;P&gt;else count_var+1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Nov 2018 21:54:04 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-11-23T21:54:04Z</dc:date>
    <item>
      <title>Count a value _ Conditional loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-a-value-Conditional-loop/m-p/515671#M139189</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to populate a count_var variable in my dataset based on the value of Order Id, Dataset format is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Order ID&amp;nbsp; &amp;nbsp;Count_var&lt;/P&gt;&lt;P&gt;000123&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;000123&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;000123&amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;000125&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;000125&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;000130&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here Count_var variable is something that I want to auto-populate in SAS, which should start the counting from 1 when the value of Order ID changes. Please help me with the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rohit&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 21:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-a-value-Conditional-loop/m-p/515671#M139189</guid>
      <dc:creator>RohitSehgal</dc:creator>
      <dc:date>2018-11-23T21:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count a value _ Conditional loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-a-value-Conditional-loop/m-p/515672#M139190</link>
      <description>&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by order_id;&lt;/P&gt;
&lt;P&gt;if first.order_id then count_var=1;&lt;/P&gt;
&lt;P&gt;else count_var+1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 21:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-a-value-Conditional-loop/m-p/515672#M139190</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-23T21:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Count a value _ Conditional loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-a-value-Conditional-loop/m-p/515674#M139191</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input Order_ID;
datalines;
000123
000123
000123
000125
000125
000130
;
run;

proc sort;
	by Order_ID;
run;

data want;
	set have;
	by Order_ID;

	if first.Order_ID then Count_var=1;
		else Count_var+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Nov 2018 21:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-a-value-Conditional-loop/m-p/515674#M139191</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-11-23T21:55:11Z</dc:date>
    </item>
  </channel>
</rss>

