<?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: flag first date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497152#M131669</link>
    <description>thank you for your answer! but i tried it failed. it keeps two records.&lt;BR /&gt;31may2003 04JAN1998 7 a&lt;BR /&gt;31may2003 20may2003 7 a&lt;BR /&gt;while i only want&lt;BR /&gt;31may2003 04JAN1998 7 a</description>
    <pubDate>Wed, 19 Sep 2018 21:23:42 GMT</pubDate>
    <dc:creator>jojozheng</dc:creator>
    <dc:date>2018-09-19T21:23:42Z</dc:date>
    <item>
      <title>flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497132#M131657</link>
      <description>&lt;P&gt;I want to find first opendate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have dataset below(not bold), I want result (&lt;STRONG&gt;bold&lt;/STRONG&gt;)to add new column firstdate: same date&amp;nbsp;with earlier opendate marked as 1, same date with same opendate by different item marked as 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; opendate&amp;nbsp; &amp;nbsp; &amp;nbsp; id&amp;nbsp; &amp;nbsp;item&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;firstdate&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;31may2003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; o4JAN1998&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a -------&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;31may2003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20may2003&amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;30jun2007&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 18jun2007&amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a-------- &lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;30jun2007&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 18jun2007&amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b---------&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Anyone knows how to do this? Thank you so much for your time!&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 20:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497132#M131657</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-19T20:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497143#M131664</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input   ( date                        opendate ) (:date9.)     id   item $      ;
 format date opendate date9.;
cards;
31may2003              04JAN1998    7     a
31may2003              20may2003    7     a
30jun2007                18jun2007     8    a   
30jun2007                18jun2007     8   b
; 

proc sql;
create table want as
select *,ifn(min(opendate)=opendate,1,.) as firstdate
from have
group by date
order by date, opendate;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 21:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497143#M131664</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-19T21:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497152#M131669</link>
      <description>thank you for your answer! but i tried it failed. it keeps two records.&lt;BR /&gt;31may2003 04JAN1998 7 a&lt;BR /&gt;31may2003 20may2003 7 a&lt;BR /&gt;while i only want&lt;BR /&gt;31may2003 04JAN1998 7 a</description>
      <pubDate>Wed, 19 Sep 2018 21:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497152#M131669</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-19T21:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497153#M131670</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input   ( date                        opendate ) (:date9.)     id   item $      ;
 format date opendate date9.;
cards;
31may2003              04JAN1998    7     a
31may2003              20may2003    7     a
30jun2007                18jun2007     8    a   
30jun2007                18jun2007     8   b
; 

proc sql;
create table want as
select *,ifn(min(opendate)=opendate,1,.) as firstdate
from have
group by date,item
having firstdate=1
order by date, opendate;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 21:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497153#M131670</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-19T21:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497156#M131672</link>
      <description>&lt;P&gt;or perhaps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;group&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;id&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,date&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Since I do not know your data&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 21:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497156#M131672</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-19T21:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497157#M131673</link>
      <description>after add having firstdate=1, it seems like dataset not complete..confused...</description>
      <pubDate>Wed, 19 Sep 2018 21:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497157#M131673</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-19T21:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497158#M131674</link>
      <description>&lt;P&gt;This is my test and result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input   ( date                        opendate ) (:date9.)     id   item $      ;
 format date opendate date9.;
cards;
31may2003              04JAN1998    7     a
31may2003              20may2003    7     a
30jun2007                18jun2007     8    a   
30jun2007                18jun2007     8   b
; 

proc sql;
create table want as
select *,ifn(min(opendate)=opendate,1,.) as firstdate
from have
group by date,item
having firstdate=1
order by date, opendate;
quit;


proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;RESULTS:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;TABLE class="systitleandfootercontainer" border="0" summary="Page Layout" width="100%" frame="void" rules="none" cellspacing="1" cellpadding="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="c systemtitle"&gt;The SAS System&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;opendate&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;id&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;item&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;firstdate&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;31MAY2003&lt;/TD&gt;
&lt;TD class="r data"&gt;04JAN1998&lt;/TD&gt;
&lt;TD class="r data"&gt;7&lt;/TD&gt;
&lt;TD class="l data"&gt;a&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;30JUN2007&lt;/TD&gt;
&lt;TD class="r data"&gt;18JUN2007&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;b&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;30JUN2007&lt;/TD&gt;
&lt;TD class="r data"&gt;18JUN2007&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;a&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 19 Sep 2018 21:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497158#M131674</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-19T21:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497159#M131675</link>
      <description>proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *,ifn(min(opendate)=opendate,1,.) as firstdate&lt;BR /&gt;from have&lt;BR /&gt;group by id, date&lt;BR /&gt;having firstdate=1&lt;BR /&gt;order by date, opendate;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;This is correct! Thank you! I really appreciate!</description>
      <pubDate>Wed, 19 Sep 2018 21:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497159#M131675</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-19T21:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497160#M131676</link>
      <description>Thank you for your answer! Can I ask what's the meaning of this?&lt;BR /&gt;ifn(min(opendate)=opendate,1,.)</description>
      <pubDate>Wed, 19 Sep 2018 21:48:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497160#M131676</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-19T21:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: flag first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497162#M131677</link>
      <description>&lt;P&gt;compute the minimum of the opendate and check if any of the opendate is equal to the minimum within the by group(group by), if it is , then assign 1 else assign&lt;STRONG&gt; .&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 21:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-first-date/m-p/497162#M131677</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-19T21:51:12Z</dc:date>
    </item>
  </channel>
</rss>

