<?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: keep rows for an ID based on a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584949#M166724</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;I may not have been able to&amp;nbsp;create&amp;nbsp;sample dataset&amp;nbsp;that completely represented original dataset&amp;nbsp;and there may be cases like the one you pointed out (also both dates did not have missing values). So wanted to&amp;nbsp;check the particular IDs and Obs. that showed up with Proc SQL. I will go with your suggestion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Aug 2019 14:47:52 GMT</pubDate>
    <dc:creator>d0816</dc:creator>
    <dc:date>2019-08-29T14:47:52Z</dc:date>
    <item>
      <title>keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584777#M166620</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have following dataset that I&amp;nbsp;sorted by first Begindate and then Entrydate. If ID has same Begin Date in multiple rows, I want to keep only&amp;nbsp;first row with that begin date. for e.g. for ID 1, I want to keep first and third row. For ID 2, keep both rows because Begin date is not same. For ID 3, keep&amp;nbsp;first&amp;nbsp;row because Begin date is same in both rows.&amp;nbsp;For ID 4, keep the row, because its the only row. (EDIT: There are other variables besides these.)&lt;/P&gt;&lt;P&gt;Dataset Have:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt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t;TD&gt;EntryDate_2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4/8/2019&lt;/TD&gt;&lt;TD&gt;4/15/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4/30/2019&lt;/TD&gt;&lt;TD&gt;8/7/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5/20/2019&lt;/TD&gt;&lt;TD&gt;8/13/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;6/3/2019&lt;/TD&gt;&lt;TD&gt;6/4/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4/15/2019&lt;/TD&gt;&lt;TD&gt;5/28/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;5/20/2019&lt;/TD&gt;&lt;TD&gt;6/20/2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 20:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584777#M166620</guid>
      <dc:creator>d0816</dc:creator>
      <dc:date>2019-08-28T20:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584780#M166623</link>
      <description>&lt;P&gt;Your source data needs to be sorted by ID, BeginDate_1, EntryDate_2.&lt;/P&gt;
&lt;P&gt;You then can get your desired result via a data step like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by id BeginDate_1;
   if first.BeginDate_1;
......
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 20:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584780#M166623</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-08-28T20:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584782#M166625</link>
      <description>&lt;P&gt;Alternatively use proc sort&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=want nodupkey;
by id begindate_1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 20:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584782#M166625</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-28T20:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584789#M166632</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $	BeginDate_1	anydtdte. EntryDate_2 mmddyy10.;
infile cards truncover;
format BeginDate_1 EntryDate_2 date9.;
cards;
1 4/8/2019 4/15/2019
1 4/8/2019 5/14/2019
1 4/30/2019 8/7/2019
2 5/20/2019 8/13/2019
2 6/3/2019 6/4/2019
3 4/15/2019 5/28/2019
3 4/15/2019 7/17/2019
4 5/20/2019 6/20/2019
run;

data want;
	do until(last.BeginDate_1);
		set have;
			by id BeginDate_1;

	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 21:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584789#M166632</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-08-28T21:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584794#M166636</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $	BeginDate_1	anydtdte. EntryDate_2 mmddyy10.;
infile cards truncover;
format BeginDate_1 EntryDate_2 date9.;
cards;
1 4/8/2019 4/15/2019
1 4/8/2019 5/14/2019
1 4/30/2019 8/7/2019
2 5/20/2019 8/13/2019
2 6/3/2019 6/4/2019
3 4/15/2019 5/28/2019
3 4/15/2019 7/17/2019
4 5/20/2019 6/20/2019
run;

proc sql;
create table want as
select distinct *
from have
group by id,BeginDate_1
having EntryDate_2=min(EntryDate_2);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 21:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584794#M166636</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-28T21:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584942#M166720</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All codes worked&amp;nbsp;in the sample dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I applied this in my original dataset, the resulting no. of obs&amp;nbsp;with codes from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;were 3187 obs but &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s code gave 3198 obs. (11 extra obs.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I check&amp;nbsp;which extra observations&amp;nbsp;are in resulting dataset from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, so that I can check for&amp;nbsp;the extra&amp;nbsp;IDs in these extra observations?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 14:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584942#M166720</guid>
      <dc:creator>d0816</dc:creator>
      <dc:date>2019-08-29T14:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584943#M166721</link>
      <description>&lt;P&gt;&lt;SPAN class="token procnames"&gt;Made a minor change: first&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;BeginDate_1&amp;nbsp; instead of last&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;BeginDate_1 in the following code. Code worked in the sample dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;do until&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;last&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;BeginDate_1&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt; BeginDate_1&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 14:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584943#M166721</guid>
      <dc:creator>d0816</dc:creator>
      <dc:date>2019-08-29T14:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584946#M166723</link>
      <description>&lt;P&gt;Possibly you have duplicates of&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;EntryDate_2 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the logic also is dependent upon other variables in the dataset that's causing even the distinct to not work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recommend go with a Datastep option posted by others. The reason I participated in the thread is to see another method of doing that wasn't posted.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 14:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584946#M166723</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-29T14:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584949#M166724</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;I may not have been able to&amp;nbsp;create&amp;nbsp;sample dataset&amp;nbsp;that completely represented original dataset&amp;nbsp;and there may be cases like the one you pointed out (also both dates did not have missing values). So wanted to&amp;nbsp;check the particular IDs and Obs. that showed up with Proc SQL. I will go with your suggestion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 14:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584949#M166724</guid>
      <dc:creator>d0816</dc:creator>
      <dc:date>2019-08-29T14:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584952#M166726</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/155169"&gt;@d0816&lt;/a&gt;&amp;nbsp; I generally tend to use MIN, MAX operator and functions when I know there are Date/Datetime values that I have to deal with as opposed to FIRST and LAST if and when possible giving some precedence to this approach(personal) of mine. The reason is that it gives me greater control and I wanna know what the heck is my code doing in my imagination. I guess this practice is a thing that stuck to me because I work with Transaction data set for the most part.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 14:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/584952#M166726</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-29T14:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: keep rows for an ID based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/672793#M202242</link>
      <description>&lt;P&gt;proc sort data = Have nodupkey out= HAVE1 ; by ID&amp;nbsp; begindate1 ; run ;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 12:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-rows-for-an-ID-based-on-a-condition/m-p/672793#M202242</guid>
      <dc:creator>chihab</dc:creator>
      <dc:date>2020-07-28T12:18:51Z</dc:date>
    </item>
  </channel>
</rss>

