<?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: Indicator for year of sale in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Indicator-for-year-of-sale/m-p/398137#M278349</link>
    <description>&lt;P&gt;TESTED CODE:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data count(rename= Year=Year_event);&lt;BR /&gt;set records;&lt;BR /&gt;by ID;&lt;BR /&gt;if first.ID then count=0;&lt;BR /&gt;if event eq 1 then count+1;&lt;BR /&gt;if count eq 1 then output;&lt;BR /&gt;drop event;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data result;&lt;BR /&gt;merge records count;&lt;BR /&gt;by ID;&lt;BR /&gt;drop count;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=result;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Sep 2017 15:19:51 GMT</pubDate>
    <dc:creator>ShrutiD</dc:creator>
    <dc:date>2017-09-22T15:19:51Z</dc:date>
    <item>
      <title>Indicator for year of sale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indicator-for-year-of-sale/m-p/397887#M278347</link>
      <description>&lt;P&gt;Hi Community&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID year event&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;2014 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;2015 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;2016 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;2014 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;2015 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;2016 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp;2014 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp;2015 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp;2016 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create an indicator that shows me the year the event happend, even for the years that the event was 0, as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID year event &amp;nbsp;year_event&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;2014 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2016&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;2015 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2016&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;2016 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2016&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;2014 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2015&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;2015 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2015&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;2016 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2015&lt;/P&gt;&lt;P&gt;3 &amp;nbsp;2014 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2014&lt;/P&gt;&lt;P&gt;3 &amp;nbsp;2015 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2014&lt;/P&gt;&lt;P&gt;3 &amp;nbsp;2016 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2014&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is highly appreciated. Sorry if it is too simple.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 19:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indicator-for-year-of-sale/m-p/397887#M278347</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2017-09-21T19:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Indicator for year of sale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indicator-for-year-of-sale/m-p/397903#M278348</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;PRE&gt;data first;&lt;BR /&gt;    set have;&lt;BR /&gt;    prev_event=lag(event);&lt;BR /&gt;    prev_id=lag(id);&lt;BR /&gt;    if id=prev_id and event=1 and prev_event=0 then output;&lt;BR /&gt;run;&lt;BR /&gt;data want;&lt;BR /&gt;    merge have first(rename=(year=year_event) drop=prev_event prev_id);&lt;BR /&gt;    by id;&lt;BR /&gt;run;&lt;BR /&gt;        
&lt;/PRE&gt;
&lt;P&gt;Assumes data is sorted by ID and year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 19:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indicator-for-year-of-sale/m-p/397903#M278348</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-21T19:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Indicator for year of sale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indicator-for-year-of-sale/m-p/398137#M278349</link>
      <description>&lt;P&gt;TESTED CODE:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data count(rename= Year=Year_event);&lt;BR /&gt;set records;&lt;BR /&gt;by ID;&lt;BR /&gt;if first.ID then count=0;&lt;BR /&gt;if event eq 1 then count+1;&lt;BR /&gt;if count eq 1 then output;&lt;BR /&gt;drop event;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data result;&lt;BR /&gt;merge records count;&lt;BR /&gt;by ID;&lt;BR /&gt;drop count;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=result;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 15:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indicator-for-year-of-sale/m-p/398137#M278349</guid>
      <dc:creator>ShrutiD</dc:creator>
      <dc:date>2017-09-22T15:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Indicator for year of sale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indicator-for-year-of-sale/m-p/398289#M278350</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID year event ;
cards;
1  2014  0
1  2015  0
1  2016  1
2  2014  0
2  2015  1
2  2016  1
3  2014  1
3  2015  1
3  2016  1
;
run;
data want;
 do until(last.id);
   set have;
   by id;
   if event and not found then do;new_year=year;found=1;end;
 end;
 do until(last.id);
   set have;
   by id;
   output;
 end;
 drop found;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Sep 2017 12:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indicator-for-year-of-sale/m-p/398289#M278350</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-09-23T12:52:11Z</dc:date>
    </item>
  </channel>
</rss>

