<?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 Panel Data: Identify the first occurrence of an event within a by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18751#M2838</link>
    <description>I have a panel data with to identifiers: ID and Time. The dataset contains the following variables: ID, Time and V1. I want to create a fourth variable Flag which will identify the first date where V1 &amp;gt; 0 for each ID. For eg: The third observations identifies the third month as the first occurrence of a positive V1 for ID = 1. Again the seventh observation identifies the second month as the first occurrence of a positive V1 for ID = 2 . Thanks in advance. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ID   Time   V1 Flag&lt;BR /&gt;
1 ,       1,      0,       0&lt;BR /&gt;
1 ,       2,      0,       0&lt;BR /&gt;
1 ,       3,      7.5,     3&lt;BR /&gt;
1 ,       4,      6,        0&lt;BR /&gt;
1 ,       5,      0,        0&lt;BR /&gt;
2 ,       1,      0,        0&lt;BR /&gt;
2 ,       2,      9,        2&lt;BR /&gt;
2 ,       3,     9,        0&lt;BR /&gt;
2 ,       4,      0,        0&lt;BR /&gt;
2 ,       5,      2.5,     0</description>
    <pubDate>Mon, 28 Feb 2011 19:22:44 GMT</pubDate>
    <dc:creator>DB_ECON</dc:creator>
    <dc:date>2011-02-28T19:22:44Z</dc:date>
    <item>
      <title>Panel Data: Identify the first occurrence of an event within a by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18751#M2838</link>
      <description>I have a panel data with to identifiers: ID and Time. The dataset contains the following variables: ID, Time and V1. I want to create a fourth variable Flag which will identify the first date where V1 &amp;gt; 0 for each ID. For eg: The third observations identifies the third month as the first occurrence of a positive V1 for ID = 1. Again the seventh observation identifies the second month as the first occurrence of a positive V1 for ID = 2 . Thanks in advance. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ID   Time   V1 Flag&lt;BR /&gt;
1 ,       1,      0,       0&lt;BR /&gt;
1 ,       2,      0,       0&lt;BR /&gt;
1 ,       3,      7.5,     3&lt;BR /&gt;
1 ,       4,      6,        0&lt;BR /&gt;
1 ,       5,      0,        0&lt;BR /&gt;
2 ,       1,      0,        0&lt;BR /&gt;
2 ,       2,      9,        2&lt;BR /&gt;
2 ,       3,     9,        0&lt;BR /&gt;
2 ,       4,      0,        0&lt;BR /&gt;
2 ,       5,      2.5,     0</description>
      <pubDate>Mon, 28 Feb 2011 19:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18751#M2838</guid>
      <dc:creator>DB_ECON</dc:creator>
      <dc:date>2011-02-28T19:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Panel Data: Identify the first occurrence of an event within a by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18752#M2839</link>
      <description>Use retain with by groups and a found flag to indicate if the variable has already been set.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data want;&lt;BR /&gt;
set have;&lt;BR /&gt;
by id;&lt;BR /&gt;
&lt;BR /&gt;
retain found;&lt;BR /&gt;
&lt;BR /&gt;
if first.id then found=0;&lt;BR /&gt;
&lt;BR /&gt;
flag=0;&lt;BR /&gt;
&lt;BR /&gt;
if v1 ne 0 and found=0 then do;&lt;BR /&gt;
flag=time;&lt;BR /&gt;
found=1;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
drop found;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 28 Feb 2011 23:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18752#M2839</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-02-28T23:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: Panel Data: Identify the first occurrence of an event within a by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18753#M2840</link>
      <description>Hi.&lt;BR /&gt;
If your data look like you post (e.g have been sorted).&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
data temp;&lt;BR /&gt;
 infile datalines dlm=' ,';&lt;BR /&gt;
 input ID Time V1;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 , 1, 0&lt;BR /&gt;
1 , 2, 0&lt;BR /&gt;
1 , 3, 7.5&lt;BR /&gt;
1 , 4, 6&lt;BR /&gt;
1 , 5, 0&lt;BR /&gt;
2 , 1, 0&lt;BR /&gt;
2 , 2, 9&lt;BR /&gt;
2 , 3, 9&lt;BR /&gt;
2 , 4, 0&lt;BR /&gt;
2 , 5, 2.5&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data temp(drop=_id);&lt;BR /&gt;
 set temp;&lt;BR /&gt;
 retain _id .;&lt;BR /&gt;
 if id ne _id and v1 gt 0 then do;&lt;BR /&gt;
                                 _id=id;&lt;BR /&gt;
                                 flag=time;&lt;BR /&gt;
                               end;&lt;BR /&gt;
   else flag=0;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Tue, 01 Mar 2011 02:26:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18753#M2840</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-03-01T02:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Panel Data: Identify the first occurrence of an event within a by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18754#M2841</link>
      <description>Thanks a lot Reeza.....This works great!!</description>
      <pubDate>Wed, 02 Mar 2011 16:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18754#M2841</guid>
      <dc:creator>DB_ECON</dc:creator>
      <dc:date>2011-03-02T16:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Panel Data: Identify the first occurrence of an event within a by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18755#M2842</link>
      <description>Thanks a lot to Ksharp as well.....This code also does the job....&lt;BR /&gt;
Thanks Guys!!!</description>
      <pubDate>Wed, 02 Mar 2011 16:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Panel-Data-Identify-the-first-occurrence-of-an-event-within-a-by/m-p/18755#M2842</guid>
      <dc:creator>DB_ECON</dc:creator>
      <dc:date>2011-03-02T16:44:43Z</dc:date>
    </item>
  </channel>
</rss>

