<?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: DATA step counting logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372328#M89013</link>
    <description>&lt;P&gt;Do you have list of "special" teams? How do you have it? How many are there?&lt;/P&gt;
&lt;P&gt;And if B is not a special team how/why does the counter get set to 1 for: 2 2 B Yes 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if this&lt;/P&gt;
&lt;P&gt;4 4 B Yes 1&amp;nbsp; &amp;lt;- again why is this counter 1&lt;BR /&gt;5 4 A No 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you may need to expand on your example some to provide a couple more examples of where the count starts and if &lt;STRONG&gt;order&lt;/STRONG&gt; matters explicitly describe the rules a bit more.&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jun 2017 23:21:06 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-06-30T23:21:06Z</dc:date>
    <item>
      <title>DATA step counting logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372319#M89007</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I couldn't come up with a relatively simple counting logic and was hoping somebody can help me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the sample table created by the code below (which includes what I want to achive as "Counter") I would like to create a counter variable that starts to count teams within each event. The only trick is, the code should start counting from 1 when a team within the event is a "special team". For instance in the event number 6 (i.e. row 7 to 10), counter gets a value of 1 only at row number 9 as within the same event team C (in row 7) and team A (row &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; are not special teams and the consequtive rows within the same event keep counting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;input N Event Team $ Special_team $ Counter;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 A No 0&lt;BR /&gt;2 2 B Yes 1&lt;BR /&gt;3 3 C No 0&lt;BR /&gt;4 4 B Yes 1&lt;BR /&gt;5 4 A No 2&lt;BR /&gt;6 5 A No 0&lt;BR /&gt;7 6 C No 0&lt;BR /&gt;8 6 A No 0&lt;BR /&gt;9 6 D Yes 1&lt;BR /&gt;10 6 C No 2&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following code but it did not work for me:&lt;/P&gt;&lt;P&gt;proc sort data=test;&lt;BR /&gt;by event;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;set test;&lt;BR /&gt;by event;&lt;BR /&gt;if special_team='Yes' and first.event then counter=1;&lt;BR /&gt;else counter+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate if you can help, especially without a SQL:)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Recep&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 23:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372319#M89007</guid>
      <dc:creator>Recep</dc:creator>
      <dc:date>2017-06-30T23:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step counting logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372328#M89013</link>
      <description>&lt;P&gt;Do you have list of "special" teams? How do you have it? How many are there?&lt;/P&gt;
&lt;P&gt;And if B is not a special team how/why does the counter get set to 1 for: 2 2 B Yes 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if this&lt;/P&gt;
&lt;P&gt;4 4 B Yes 1&amp;nbsp; &amp;lt;- again why is this counter 1&lt;BR /&gt;5 4 A No 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you may need to expand on your example some to provide a couple more examples of where the count starts and if &lt;STRONG&gt;order&lt;/STRONG&gt; matters explicitly describe the rules a bit more.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 23:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372328#M89013</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-30T23:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step counting logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372339#M89019</link>
      <description>&lt;P&gt;The column "special_team" tells about it (Yes vs. No). I hope the SAS code I included&amp;nbsp;produces the right data for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B is a special team.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Recep&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 23:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372339#M89019</guid>
      <dc:creator>Recep</dc:creator>
      <dc:date>2017-06-30T23:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step counting logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372340#M89020</link>
      <description>&lt;P&gt;As long as any special team is in the event, then you count the teams?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sort data=have;
By event DESCENDING special_team;

Data want;
Set have;

By event;

If first.event and special_team='Yes' then team=1;
Else if not first.event and team &amp;gt; = 1 then team+1;
Else team=0;

Run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 01 Jul 2017 00:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372340#M89020</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-01T00:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step counting logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372341#M89021</link>
      <description>&lt;P&gt;That's correct. That's when I start to count from 1 and continue within the same event without checking whether the consecutive team is special or not.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jul 2017 00:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372341#M89021</guid>
      <dc:creator>Recep</dc:creator>
      <dc:date>2017-07-01T00:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step counting logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372342#M89022</link>
      <description>&lt;P&gt;I'll test your proposed code...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot...&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jul 2017 00:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-step-counting-logic/m-p/372342#M89022</guid>
      <dc:creator>Recep</dc:creator>
      <dc:date>2017-07-01T00:03:28Z</dc:date>
    </item>
  </channel>
</rss>

