<?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: cumulative count under condtion in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/cumulative-count-under-condtion/m-p/843263#M82240</link>
    <description>Hi,&lt;BR /&gt;I found that this will work that is add one more line for if clause&lt;BR /&gt;as&lt;BR /&gt;data event_program_more;&lt;BR /&gt;set event_program;&lt;BR /&gt;by permno program_code ;&lt;BR /&gt;retain counter_overall;&lt;BR /&gt;if first.program_code then counter_overall=1;&lt;BR /&gt;else counter_overall = counter_overall+1;&lt;BR /&gt;if counter_overall &amp;gt; program_code then counter_overall=1;&lt;BR /&gt;&lt;BR /&gt;run;</description>
    <pubDate>Wed, 09 Nov 2022 00:20:11 GMT</pubDate>
    <dc:creator>Zhongda</dc:creator>
    <dc:date>2022-11-09T00:20:11Z</dc:date>
    <item>
      <title>cumulative count under condtion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/cumulative-count-under-condtion/m-p/843033#M82224</link>
      <description>&lt;P&gt;Hi ALL,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ma trying to count the varible in the group call counter_overall, but my code does not work for this special case below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is the dataset:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PERMNO&lt;/TD&gt;&lt;TD&gt;EVTDATE&lt;/TD&gt;&lt;TD&gt;RET&lt;/TD&gt;&lt;TD&gt;DATE&lt;/TD&gt;&lt;TD&gt;days_to_previous_p&lt;/TD&gt;&lt;TD&gt;days_to_next&lt;/TD&gt;&lt;TD&gt;first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gt;0.004&lt;/TD&gt;&lt;TD&gt;5/10/07&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the counter_overall is the target I want but the numbers are wrong and the next column correct_overall is the right numbers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;basically, if you take a look at the varible : program_code, for this case, it is 2,2,2,2. 2 means two event in a program and then with this program, the program_code is 2,2 and&amp;nbsp;&lt;/P&gt;&lt;P&gt;2,2,2,2 here means, for permno 10028, there are two successive "two event program", my target is to number the sequence of the event in these two events groups.&lt;/P&gt;&lt;P&gt;so there is an invisible condition that is the counter_overall can not access the number of program code. Sorry I know it is quite confused , but let me explain it in another case:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;suppose there is another stock permno 10000, and it has two successive three-event programs.&lt;/P&gt;&lt;P&gt;so the program code for this 6 obs is 3,3,3 , 3,3,3&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and I would like to number the sequence as 1,2,3 1,2,3 instead of 1,2,3,4,5,6.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my code but it does not work FYI:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc sort data = event_program;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;by permno program_code;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;data event_program_more;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set event_program;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;by &amp;nbsp;permno program_code ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;retain counter_overall;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if first.program_code then counter_overall=1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else counter_overall = counter_overall+1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Again, thanks a lot for the help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Zhongda&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 06:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/cumulative-count-under-condtion/m-p/843033#M82224</guid>
      <dc:creator>Zhongda</dc:creator>
      <dc:date>2022-11-08T06:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: cumulative count under condtion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/cumulative-count-under-condtion/m-p/843263#M82240</link>
      <description>Hi,&lt;BR /&gt;I found that this will work that is add one more line for if clause&lt;BR /&gt;as&lt;BR /&gt;data event_program_more;&lt;BR /&gt;set event_program;&lt;BR /&gt;by permno program_code ;&lt;BR /&gt;retain counter_overall;&lt;BR /&gt;if first.program_code then counter_overall=1;&lt;BR /&gt;else counter_overall = counter_overall+1;&lt;BR /&gt;if counter_overall &amp;gt; program_code then counter_overall=1;&lt;BR /&gt;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 09 Nov 2022 00:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/cumulative-count-under-condtion/m-p/843263#M82240</guid>
      <dc:creator>Zhongda</dc:creator>
      <dc:date>2022-11-09T00:20:11Z</dc:date>
    </item>
  </channel>
</rss>

