<?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 the first date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/flag-the-first-date/m-p/628453#M185707</link>
    <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72105"&gt;@lillymaginta&lt;/a&gt;&amp;nbsp; Your sample is all "sets of 2 records for each id", is it really a representative sample. Well, assuming I understand your requirement, here is a SQL solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id$2. start  end drug ;
attrib start format =date9. informat=date9.;
attrib end format =date9. informat=date9.;
datalines;
1 01JAN2015 14FEB2015 0
1 18FEB2015 30APR2015 1
2 01jan2015 28JAN2015  1
2 01apr2015 30apr2015   1
3 01JAN2015 14FEB2015 1
3 01JAN2015 14FEB2015 0
;
run;

proc sql;
create table want as
select *
from 
(select * from test group by id,start,end having not(count(*)&amp;gt;1 and sum(drug)))
group by id
having min(start)=start;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 29 Feb 2020 15:49:05 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-02-29T15:49:05Z</dc:date>
    <item>
      <title>flag the first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-the-first-date/m-p/628451#M185705</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id$2. start  end drug ;
attrib start format =date9. informat=date9.;
attrib end format =date9. informat=date9.;
datalines;
1 01JAN2015 14FEB2015 0
1 18FEB2015 30APR2015 1
2 01jan2015 28JAN2015  1
2 01apr2015 30apr2015   1
3 01JAN2015 14FEB2015 1
3 01JAN2015 14FEB2015 0
;&lt;BR /&gt;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I have the following data. I want to flag the first date, keep the id, drug. If the id have both drug 0 and drug 1 on the same date then delete.&lt;/P&gt;&lt;P&gt;Output&amp;nbsp; data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 01JAN2015 14FEB2015 0
2 01jan2015 28JAN2015  1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Feb 2020 15:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-the-first-date/m-p/628451#M185705</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2020-02-29T15:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: flag the first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-the-first-date/m-p/628453#M185707</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72105"&gt;@lillymaginta&lt;/a&gt;&amp;nbsp; Your sample is all "sets of 2 records for each id", is it really a representative sample. Well, assuming I understand your requirement, here is a SQL solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id$2. start  end drug ;
attrib start format =date9. informat=date9.;
attrib end format =date9. informat=date9.;
datalines;
1 01JAN2015 14FEB2015 0
1 18FEB2015 30APR2015 1
2 01jan2015 28JAN2015  1
2 01apr2015 30apr2015   1
3 01JAN2015 14FEB2015 1
3 01JAN2015 14FEB2015 0
;
run;

proc sql;
create table want as
select *
from 
(select * from test group by id,start,end having not(count(*)&amp;gt;1 and sum(drug)))
group by id
having min(start)=start;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Feb 2020 15:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-the-first-date/m-p/628453#M185707</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-29T15:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: flag the first date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-the-first-date/m-p/628455#M185708</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Feb 2020 16:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-the-first-date/m-p/628455#M185708</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2020-02-29T16:02:06Z</dc:date>
    </item>
  </channel>
</rss>

