<?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 SAS dataset count winning streak on baseball in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-count-winning-streak-on-baseball/m-p/282047#M311401</link>
    <description>&lt;P&gt;Hi: I am processing baseball dataset. I want to count the winning streak of a team winning. I created a variable called win, if team A wins it is 1, else it is 0. I want to create a variable called winstreak, if team A wins 1 time, it is 1, if team A wins 2 in a row, it is 2, Once&amp;nbsp;team A loses it goes back to 0 again. So far I have tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data phi2002;
set phi2002;
if (VisitingTeam = "PHI" and VisitorRunsScored &amp;gt; HomeRunsScore)
then PHIWIN = 1;
else if (HomeTeam = "PHI" and HomeRunsScore &amp;gt; VisitorRunsScored)
then PHIWIN = 1;
else PHIWIN = 0;
retain winstreak;
if PHIWIN = 1 then winstreak =+1;
else winstreak = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code doesnt work, since winstreak only shows the same value as PHIWIN. Please help!&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jul 2016 19:55:19 GMT</pubDate>
    <dc:creator>psychopedia</dc:creator>
    <dc:date>2016-07-04T19:55:19Z</dc:date>
    <item>
      <title>SAS dataset count winning streak on baseball</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-count-winning-streak-on-baseball/m-p/282047#M311401</link>
      <description>&lt;P&gt;Hi: I am processing baseball dataset. I want to count the winning streak of a team winning. I created a variable called win, if team A wins it is 1, else it is 0. I want to create a variable called winstreak, if team A wins 1 time, it is 1, if team A wins 2 in a row, it is 2, Once&amp;nbsp;team A loses it goes back to 0 again. So far I have tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data phi2002;
set phi2002;
if (VisitingTeam = "PHI" and VisitorRunsScored &amp;gt; HomeRunsScore)
then PHIWIN = 1;
else if (HomeTeam = "PHI" and HomeRunsScore &amp;gt; VisitorRunsScored)
then PHIWIN = 1;
else PHIWIN = 0;
retain winstreak;
if PHIWIN = 1 then winstreak =+1;
else winstreak = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code doesnt work, since winstreak only shows the same value as PHIWIN. Please help!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2016 19:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-count-winning-streak-on-baseball/m-p/282047#M311401</guid>
      <dc:creator>psychopedia</dc:creator>
      <dc:date>2016-07-04T19:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS dataset count winning streak on baseball</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-count-winning-streak-on-baseball/m-p/282048#M311402</link>
      <description>&lt;P&gt;Please post sample data and expected output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2016 19:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-count-winning-streak-on-baseball/m-p/282048#M311402</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-04T19:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS dataset count winning streak on baseball</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-count-winning-streak-on-baseball/m-p/282065#M311403</link>
      <description>&lt;P&gt;Your problem is with the line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if PHIWIN = 1 then winstreak =+1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you're doing here is setting the value of winstreak to 1 instead of incrementing it. if you make it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if PHIWIN = 1 then winstreak+1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you'll find you get the correct answer.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2016 23:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-count-winning-streak-on-baseball/m-p/282065#M311403</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2016-07-04T23:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS dataset count winning streak on baseball</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-count-winning-streak-on-baseball/m-p/282219#M311404</link>
      <description>&lt;P&gt;Winning and loosing streaks in 2010:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bb0;
infile "&amp;amp;sasforum\datasets\GL2010.txt" dsd;
input date :$8. gameNumber :$1. day :$3. 
    teamV :$3. leagueV :$2. gameV
    teamH :$3. leagueH :$2. gameH
    scoreV scoreH;
run;

data bb;
set bb0;
length game $9 team $7;
game = cats(date, gameNumber);
team = catx("-", teamV, leagueV);
location = "V";
teamScore = scoreV; opponentScore = scoreH;
win = teamScore &amp;gt; opponentScore;
output;
team = catx("-", teamH, leagueH);
location = "H";
teamScore = scoreH; opponentScore = scoreV;
win = teamScore &amp;gt; opponentScore;
output;
keep game team location win teamScore opponentScore;
run;

proc sort data=bb; by team game; run;

data streaks;
streak = 0;
do until (last.win);
    set bb; by team win notsorted;
    streak + 1;
    end;
keep team win streak;
run;

proc format;
value win
0 = "Loosing"
1 = "Winning"
;
run;

proc sql;
create table teamStreaks as
select team, win format=win., max(streak) as longestStreak
from streaks
group by team, win;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jul 2016 17:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-count-winning-streak-on-baseball/m-p/282219#M311404</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-07-05T17:19:39Z</dc:date>
    </item>
  </channel>
</rss>

