<?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 record has same date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/flag-record-has-same-date/m-p/496793#M131484</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :$3.    id    first;
cards;
MAY     1     1
MAY     1     . 
JUN      1    .     
SEP     2     1
SEP     2     .  
;

proc sort data=have;
by date;
run;


data want;
do until(last.date);
set have;
by date;
retain cnt;
if first.date then cnt=1;
else cnt+1;
end;
do until(last.date);
set have;
by date;
if cnt&amp;gt;1 then flag=1;
else flag=.;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 18 Sep 2018 23:20:05 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2018-09-18T23:20:05Z</dc:date>
    <item>
      <title>flag record has same date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-record-has-same-date/m-p/496789#M131481</link>
      <description>&lt;P&gt;I have a dataset below:&lt;/P&gt;&lt;P&gt;date&amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp;&amp;nbsp;first&lt;/P&gt;&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JUN&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;SEP&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;SEP&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want record with same date to mark as first=1, like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date&amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp;&amp;nbsp;first&lt;/P&gt;&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;JUN&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;SEP&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;SEP&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;group by id date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cannot use retain, cause it failed as&amp;nbsp;&lt;/P&gt;&lt;P&gt;date&amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp;&amp;nbsp;first&lt;/P&gt;&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;JUN&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -----------I don't want JUN to be as first=1, I just want all same date MAY to be first=1.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 22:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-record-has-same-date/m-p/496789#M131481</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-18T22:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: flag record has same date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-record-has-same-date/m-p/496792#M131483</link>
      <description>&lt;P&gt;Why did you start a new thread?&lt;/P&gt;
&lt;P&gt;What's wrong with the one you created &lt;A href="https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496713#M131436" target="_self"&gt;here&lt;/A&gt;?&lt;/P&gt;
&lt;P&gt;Did you try all the&amp;nbsp;solutions given (including &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;'s?&lt;/P&gt;
&lt;P&gt;If you did, explain why they don't suit.&lt;/P&gt;
&lt;P&gt;And of course, clearly &lt;STRONG&gt;provide the expected output.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 23:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-record-has-same-date/m-p/496792#M131483</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-18T23:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: flag record has same date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-record-has-same-date/m-p/496793#M131484</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :$3.    id    first;
cards;
MAY     1     1
MAY     1     . 
JUN      1    .     
SEP     2     1
SEP     2     .  
;

proc sort data=have;
by date;
run;


data want;
do until(last.date);
set have;
by date;
retain cnt;
if first.date then cnt=1;
else cnt+1;
end;
do until(last.date);
set have;
by date;
if cnt&amp;gt;1 then flag=1;
else flag=.;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Sep 2018 23:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-record-has-same-date/m-p/496793#M131484</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-09-18T23:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: flag record has same date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-record-has-same-date/m-p/496798#M131488</link>
      <description>&lt;P&gt;What about September?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're correct that RETAIN may not work - and it likely own't with a variable already present. But if you create a new variable and work with that it will work fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input date :$3. id first;
    cards;
MAY     1     1
MAY     1     . 
JUN      1    .     
SEP     2     1
SEP     2     .  
;

data temp;
    set have;
    by date notsorted;
    retain flag;

    if first.date and first=1 then
        flag=1;
    else if first.date then
        call missing(flag);
run;

data want;
    set temp;
    where flag=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215650"&gt;@jojozheng&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset below:&lt;/P&gt;
&lt;P&gt;date&amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp;&amp;nbsp;first&lt;/P&gt;
&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;JUN&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;SEP&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;SEP&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want record with same date to mark as first=1, like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date&amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp;&amp;nbsp;first&lt;/P&gt;
&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;JUN&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;SEP&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;SEP&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;group by id date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cannot use retain, cause it failed as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date&amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp;&amp;nbsp;first&lt;/P&gt;
&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;MAY&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;JUN&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -----------I don't want JUN to be as first=1, I just want all same date MAY to be first=1.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 00:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-record-has-same-date/m-p/496798#M131488</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-19T00:18:24Z</dc:date>
    </item>
  </channel>
</rss>

