<?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: flagging previous events in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370637#M275796</link>
    <description>&lt;P&gt;The following should work:&lt;/P&gt;
&lt;PRE&gt;data want (drop=hold);
  set have;
  by Company;
  retain hold;
  if first.Company then hold='N';
  Flag=hold;
  output;
  if Win_Lose eq 'W' then hold='Y';
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Jun 2017 15:49:18 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-06-26T15:49:18Z</dc:date>
    <item>
      <title>flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370631#M275794</link>
      <description>&lt;P&gt;Here is what my data looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Company&lt;/TD&gt;&lt;TD&gt;Project&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Win_Lose&lt;/TD&gt;&lt;TD&gt;Flag Needed (previous win ever)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Project1&lt;/TD&gt;&lt;TD&gt;date1&lt;/TD&gt;&lt;TD&gt;L&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Project2&lt;/TD&gt;&lt;TD&gt;date2&lt;/TD&gt;&lt;TD&gt;W&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Project&lt;/SPAN&gt;3&lt;/TD&gt;&lt;TD&gt;date3&lt;/TD&gt;&lt;TD&gt;L&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Project&lt;/SPAN&gt;4&lt;/TD&gt;&lt;TD&gt;date4&lt;/TD&gt;&lt;TD&gt;W&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Project&lt;/SPAN&gt;5&lt;/TD&gt;&lt;TD&gt;date4&lt;/TD&gt;&lt;TD&gt;W&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Project&lt;/SPAN&gt;6&lt;/TD&gt;&lt;TD&gt;date5&lt;/TD&gt;&lt;TD&gt;L&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Project&lt;/SPAN&gt;7&lt;/TD&gt;&lt;TD&gt;date6&lt;/TD&gt;&lt;TD&gt;W&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Project&lt;/SPAN&gt;1&lt;/TD&gt;&lt;TD&gt;date1&lt;/TD&gt;&lt;TD&gt;L&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Project&lt;/SPAN&gt;2&lt;/TD&gt;&lt;TD&gt;date2&lt;/TD&gt;&lt;TD&gt;L&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Project&lt;/SPAN&gt;3&lt;/TD&gt;&lt;TD&gt;date3&lt;/TD&gt;&lt;TD&gt;W&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Project&lt;/SPAN&gt;4&lt;/TD&gt;&lt;TD&gt;date4&lt;/TD&gt;&lt;TD&gt;L&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create flag that shows for each project if there was a winning project within the same company anytime prior to that project. I was trying to use lag() but that only help with the project directly preceding the one in question. And yes i meant to write date4 twice. Some times there are multiple projects at same date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;D&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 15:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370631#M275794</guid>
      <dc:creator>darb</dc:creator>
      <dc:date>2017-06-26T15:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370636#M275795</link>
      <description>&lt;P&gt;The fact that two projects can have the same date (when one is a win and one is a loss) complicates things just a little.&amp;nbsp; Here's a way to overcome that, assuming your data set is already sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;do until (last.company);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by company;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if win_lose='W' and first_win_date=. then first_win_date = date;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (last.company);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by company;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if date &amp;lt;= first_win_date then flag='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else flag='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop first_win_date;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 15:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370636#M275795</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-26T15:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370637#M275796</link>
      <description>&lt;P&gt;The following should work:&lt;/P&gt;
&lt;PRE&gt;data want (drop=hold);
  set have;
  by Company;
  retain hold;
  if first.Company then hold='N';
  Flag=hold;
  output;
  if Win_Lose eq 'W' then hold='Y';
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 15:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370637#M275796</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-26T15:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370646#M275797</link>
      <description>&lt;P&gt;The data came out really wonky...confused as to where the first_win_date is coming from...Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 16:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370646#M275797</guid>
      <dc:creator>darb</dc:creator>
      <dc:date>2017-06-26T16:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370648#M275798</link>
      <description>&lt;P&gt;I would first make sure your data is sorted by Company and then by Date in case there are instances where you have two projects with the same date and one is a "W" and the other is an "L"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For your problem, if you use a retain statement in your data step then your lag() function will work in the way you want it to.&lt;/P&gt;&lt;P&gt;Running this should give you your desired output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by company date;
run;

data want;
set have;
by Company;
Retain flag;
if first.Company then flag = "N";
If lag(Win_Lose) = "W" then flag = "Y";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Jun 2017 16:15:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370648#M275798</guid>
      <dc:creator>jdwaterman91</dc:creator>
      <dc:date>2017-06-26T16:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370649#M275799</link>
      <description>&lt;P&gt;It's my understanding that lag only looks at&amp;nbsp;the most previous observation and not all previous observations? is that true in this case?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 16:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370649#M275799</guid>
      <dc:creator>darb</dc:creator>
      <dc:date>2017-06-26T16:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370650#M275800</link>
      <description>&lt;P&gt;This almost worked completely! However, there are instances where there are only two projects but the dates are the same:&lt;/P&gt;&lt;P&gt;I attached the data, you can see the last two observations have the same date, and they are the same company (you can't see that part) with no other previous projects. The first flag is N, and the second flag is Y, but they should both be N.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13986iB7EF7F6624BE2A62/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="data.PNG" title="data.PNG" /&gt;</description>
      <pubDate>Mon, 26 Jun 2017 16:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370650#M275800</guid>
      <dc:creator>darb</dc:creator>
      <dc:date>2017-06-26T16:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370651#M275801</link>
      <description>&lt;P&gt;Wonky?&amp;nbsp; Should be perfect, as long as the data coming in is sorted BY COMPANY DATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps if you were to show the log of your program, it could be debugged.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 16:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370651#M275801</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-26T16:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370652#M275802</link>
      <description>&lt;P&gt;Yes. Flag will equal "N" when the it is the first observation for a company and the retain statement will cause flag to equal "N" until a "W" is encountered for the previous Win_Lose value. &amp;nbsp;Then the retain statement will cause flag to equal "Y" until the evaluating the data for a different company.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 16:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370652#M275802</guid>
      <dc:creator>jdwaterman91</dc:creator>
      <dc:date>2017-06-26T16:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370653#M275803</link>
      <description>&lt;P&gt;So this is the code I used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data = test4;&lt;BR /&gt;by account_name created_date;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data test5; do until (last.account_name);&lt;BR /&gt;set test4;&lt;BR /&gt;by account_name;&lt;BR /&gt;if stage = "Closed Won" and first_win_date =. then first_win_date = created_date;&lt;BR /&gt;end;&lt;BR /&gt;do until (last.account_name);&lt;BR /&gt;set test4;&lt;BR /&gt;by account_name;&lt;BR /&gt;if created_date&amp;lt;=first_win_date then flag="N";&lt;BR /&gt;else flag ="Y";&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;drop first_win_date;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and i attached some output...you can see the flags dont make sense with regards closed lost or closed won. the count variable indicates if is the same company or not (1 means new company, 2,3....means diff project same company). The log doesnt find any issues.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13987i458A6B71C2C09D9F/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="data1.PNG" title="data1.PNG" /&gt;</description>
      <pubDate>Mon, 26 Jun 2017 16:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370653#M275803</guid>
      <dc:creator>darb</dc:creator>
      <dc:date>2017-06-26T16:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370655#M275804</link>
      <description>&lt;P&gt;that worked as well, just my only problem is that sometimes there are multiple projects on the same date with no prior projects (so it logs the first date as N, but then the next ones on the same date as Y, when in fact they should all be N&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 16:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370655#M275804</guid>
      <dc:creator>darb</dc:creator>
      <dc:date>2017-06-26T16:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370668#M275805</link>
      <description>&lt;P&gt;OK, let's try a slight variation.&amp;nbsp; This statement gets replaced:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if created_date&amp;lt;=first_win_date then flag="N";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if &lt;FONT color="#ff0000"&gt;first_win_date=. or&lt;/FONT&gt; created_date&amp;lt;=first_win_date then flag="N";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, if your real data set is large this can be rolled up into one loop instead of two.&amp;nbsp; First step, though, is to get the logic working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366ff"&gt;As long as everybody else is updating their solutions, here's my update:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366ff"&gt;data test5; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366ff"&gt;do until (last.account_name);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp;&amp;nbsp; set test4;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp;&amp;nbsp; by account_name;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp;&amp;nbsp; if stage = "Closed Won" and first_win_date =. then first_win_date = created_date;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp;&amp;nbsp; if (first_win_date = . ) or (created_date &amp;lt;= first_win_date) then flag='N';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366ff"&gt;&amp;nbsp;&amp;nbsp; else flag='Y';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;FONT color="#3366ff"&gt;output;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366ff"&gt;end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366ff"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 18:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370668#M275805</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-26T18:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370690#M275806</link>
      <description>&lt;P&gt;I think the following will account for your same date criterion. You hadn't mentioned that in your initial post:&lt;/P&gt;
&lt;PRE&gt;data want (drop=_:);&lt;BR /&gt; set have;&lt;BR /&gt; by Company;&lt;BR /&gt; length _got_w $1;&lt;BR /&gt; length _first_date $8;&lt;BR /&gt; retain _got_W _first_date;&lt;BR /&gt; if first.Company then do;&lt;BR /&gt;   _got_W='N';&lt;BR /&gt; end;&lt;BR /&gt; if _got_W eq 'N' and Win_Lose eq 'W' then do;&lt;BR /&gt;   _got_W='Y';&lt;BR /&gt;   _first_date=date;&lt;BR /&gt; end;&lt;BR /&gt; Flag=ifc(date gt _first_date and _got_W eq 'Y','Y','N');&lt;BR /&gt; output;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: above code modified 26Jun2017 at 4:20p.m.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 20:20:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370690#M275806</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-26T20:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370709#M275807</link>
      <description>&lt;P&gt;Ok. &amp;nbsp;Try making this adjustment and see if that fixes your problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by company date;
run;

data have;
set want;
by Company;
Retain flag;
If first.Company then flag = "N";
If (lag(Win_Lose) = "W" and lag(date) ^= date and lag(company) = company) then flag = "Y";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Jun 2017 18:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370709#M275807</guid>
      <dc:creator>jdwaterman91</dc:creator>
      <dc:date>2017-06-26T18:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370716#M275808</link>
      <description>thank you! all good &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 26 Jun 2017 19:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370716#M275808</guid>
      <dc:creator>darb</dc:creator>
      <dc:date>2017-06-26T19:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370720#M275809</link>
      <description>&lt;P&gt;Art, despite having a correctly marked solution, you might have some tweaking to do.&amp;nbsp; Try your program with this data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;data &lt;/FONT&gt;&lt;FONT face="Lucida Console" size="2"&gt;test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;company='A';&lt;/P&gt;
&lt;P&gt;do date = 1, 5;&lt;/P&gt;
&lt;P&gt;do win_lose = 'W', 'L';&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 19:23:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370720#M275809</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-26T19:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370745#M275810</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;: Good catch. I had to make a slight change to your example because, according to the original specs, date is a character variable. If it turns out to be a numeric variable, the length statement in the following would have to be changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151031"&gt;@darb&lt;/a&gt;:&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;was correct and my suggested code wouldn't correctly capture all conditions. I think that the following will and I will adjust my original code accordingly:&lt;/P&gt;
&lt;PRE&gt;data want (drop=_:);
  set have;
  by Company;
  length _got_w $1;
  length  _first_date $8;
  retain _got_W _first_date;
  if first.Company then do;
    _got_W='N';
  end;
  if _got_W eq 'N' and Win_Lose eq 'W' then do;
    _got_W='Y';
    _first_date=date;
  end;
  Flag=ifc(date gt _first_date and _got_W eq 'Y','Y','N');
  output;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 20:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370745#M275810</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-26T20:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: flagging previous events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370895#M275811</link>
      <description>&lt;P&gt;Assuming I understand your quesiton.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Company	Project	Date	Win_Lose) (: $20.);
cards;
A	Project1	date1	L	
A	Project2	date2	W	
A	Project3	date3	L	
A	Project4	date4	W	
A	Project5	date4	W	
A	Project6	date5	L	
A	Project7	date6	W	
B	Project1	date1	L	
B	Project2	date2	L	
B	Project3	date3	W	
B	Project4	date4	L
;
run;

data want;
 set have;
 by company;
 retain found 0 flag 'N';
 if first.company then do;found=0;flag='N';end;
 if lag(Win_Lose)='W' and company=lag(company) and not found then do;
   flag='Y';found=1;
 end;
 drop found;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Jun 2017 12:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flagging-previous-events/m-p/370895#M275811</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-27T12:46:53Z</dc:date>
    </item>
  </channel>
</rss>

