<?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: Delete observations in a by variable group on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/234212#M42814</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I believe if you don't select the earliest return date which satifies condition&amp;nbsp;&lt;SPAN&gt;"_date &amp;gt;= Transaction_Date" then you are at risk to miss some returns. Consider the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Rec_No&lt;/TD&gt;&lt;TD&gt;Customer_Id&lt;/TD&gt;&lt;TD&gt;Transaction_Date&lt;/TD&gt;&lt;TD&gt;Amount&lt;/TD&gt;&lt;TD&gt;Sales_Credit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1-Nov-15&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2-Nov-15&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3-Nov-15&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4-Nov-15&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you use record 4 to remove record 1 then the pair record 2/record 3 won't satisfy condition&amp;nbsp;&lt;SPAN&gt;"_date &amp;gt;= Transaction_Date" and you'll miss the removal of record 3.&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for your following up and your point is well taken. However, if OP unfortunately&amp;nbsp;has data like that, the problem is beyond a simple code fix. Surely you will have your 'balance sheet', but you will never&amp;nbsp;know if paired transations are the actual pairs without more information. If the purpose is just to get the net 'balance', then the condition of '&lt;SPAN&gt;_date &amp;gt;= Transaction_Date' can be completely ignored. Given the data as is, my approach is to get as far as the 'known' can stand, and stop right at the point where 'unknown' starts.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Just my 2cents,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Haikuo&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Nov 2015 15:57:20 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2015-11-11T15:57:20Z</dc:date>
    <item>
      <title>Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233911#M42731</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like this,&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer_Id&lt;/TD&gt;&lt;TD&gt;Transaction_No&lt;/TD&gt;&lt;TD&gt;Transaction_Date&lt;/TD&gt;&lt;TD&gt;Amount&lt;/TD&gt;&lt;TD&gt;Sales_Credit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4699&lt;/TD&gt;&lt;TD&gt;80902288&lt;/TD&gt;&lt;TD&gt;22-Sep-15&lt;/TD&gt;&lt;TD&gt;55.3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4699&lt;/TD&gt;&lt;TD&gt;80686478&lt;/TD&gt;&lt;TD&gt;12-Sep-15&lt;/TD&gt;&lt;TD&gt;62.3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4699&lt;/TD&gt;&lt;TD&gt;80687203&lt;/TD&gt;&lt;TD&gt;12-Sep-15&lt;/TD&gt;&lt;TD&gt;55.3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4919&lt;/TD&gt;&lt;TD&gt;81735223&lt;/TD&gt;&lt;TD&gt;12-Oct-15&lt;/TD&gt;&lt;TD&gt;15.99&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4919&lt;/TD&gt;&lt;TD&gt;80917293&lt;/TD&gt;&lt;TD&gt;22-Sep-15&lt;/TD&gt;&lt;TD&gt;15.99&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4919&lt;/TD&gt;&lt;TD&gt;80917294&lt;/TD&gt;&lt;TD&gt;22-Sep-15&lt;/TD&gt;&lt;TD&gt;15.99&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4919&lt;/TD&gt;&lt;TD&gt;80938352&lt;/TD&gt;&lt;TD&gt;22-Sep-15&lt;/TD&gt;&lt;TD&gt;23.99&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6320&lt;/TD&gt;&lt;TD&gt;80926085&lt;/TD&gt;&lt;TD&gt;23-Sep-15&lt;/TD&gt;&lt;TD&gt;51.75&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6320&lt;/TD&gt;&lt;TD&gt;80517713&lt;/TD&gt;&lt;TD&gt;09-Sep-15&lt;/TD&gt;&lt;TD&gt;51.75&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6320&lt;/TD&gt;&lt;TD&gt;80512633&lt;/TD&gt;&lt;TD&gt;09-Sep-15&lt;/TD&gt;&lt;TD&gt;51.75&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to find only the data with actual sales. Like in customer_id "4699" only the second observation remains. However with customer_id= "4919" I need to randomly delete either of the two observations having amount 15.99. Could you help me how to proceed with this? If statements with first.variable concept or proc sql?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 21:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233911#M42731</guid>
      <dc:creator>SASEnthusiast</dc:creator>
      <dc:date>2015-11-09T21:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233915#M42732</link>
      <description>&lt;P&gt;Can you describe why you wish to perform those actions?&lt;/P&gt;
&lt;P&gt;And define "actual sale", it&amp;nbsp;isn't self explanatory.&lt;/P&gt;
&lt;P&gt;Reducing&amp;nbsp;records be randomly deletes, AND keep details (in your case&amp;nbsp;transaction number) - why? It's "dangerous, since the details&amp;nbsp;it's not a fact any more.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would simply&amp;nbsp;combine a filter with select distinct.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 21:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233915#M42732</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-11-09T21:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233918#M42733</link>
      <description>&lt;P&gt;I am sorry to miss that information. When sales_credit= 2, it refers to a "Product return". Therefore by removing that observation and the observation with similar amount within the customer_id I am trying to achieve only those observations that show actual sales.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And yes, I agree the transaction_id is not required once I randomly select data.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 21:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233918#M42733</guid>
      <dc:creator>SASEnthusiast</dc:creator>
      <dc:date>2015-11-09T21:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233922#M42734</link>
      <description>&lt;P&gt;Can you guarantee that there will always be an exact match when it's a 2?&lt;/P&gt;
&lt;P&gt;And do you need sale dates?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 22:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233922#M42734</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-09T22:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233923#M42735</link>
      <description>&lt;P&gt;Yes, I can. Although there can be multiple 2's for one customer_id with its respective purchase transaction.&lt;/P&gt;
&lt;P&gt;Like this:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 325pt;" border="0" width="325" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 65pt;" span="5" width="65" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="65" height="15" align="right" style="height: 15.0pt; width: 65pt;"&gt;16759&lt;/TD&gt;
&lt;TD width="65" align="right" style="width: 65pt;"&gt;80902332&lt;/TD&gt;
&lt;TD width="65" align="right" class="xl63" style="width: 65pt;"&gt;22-Sep-15&lt;/TD&gt;
&lt;TD width="65" align="right" style="width: 65pt;"&gt;19.99&lt;/TD&gt;
&lt;TD width="65" align="right" style="width: 65pt;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="15" align="right" style="height: 15.0pt;"&gt;16759&lt;/TD&gt;
&lt;TD align="right"&gt;80902327&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;22-Sep-15&lt;/TD&gt;
&lt;TD align="right"&gt;19.99&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="15" align="right" style="height: 15.0pt;"&gt;16759&lt;/TD&gt;
&lt;TD align="right"&gt;80902328&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;22-Sep-15&lt;/TD&gt;
&lt;TD align="right"&gt;19.99&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="15" align="right" style="height: 15.0pt;"&gt;16759&lt;/TD&gt;
&lt;TD align="right"&gt;80902326&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;22-Sep-15&lt;/TD&gt;
&lt;TD align="right"&gt;19.99&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="15" align="right" style="height: 15.0pt;"&gt;16759&lt;/TD&gt;
&lt;TD align="right"&gt;80902335&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;22-Sep-15&lt;/TD&gt;
&lt;TD align="right"&gt;19.99&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="15" align="right" style="height: 15.0pt;"&gt;16759&lt;/TD&gt;
&lt;TD align="right"&gt;80159162&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;05-Sep-15&lt;/TD&gt;
&lt;TD align="right"&gt;19.99&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="15" align="right" style="height: 15.0pt;"&gt;16759&lt;/TD&gt;
&lt;TD align="right"&gt;80161144&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;05-Sep-15&lt;/TD&gt;
&lt;TD align="right"&gt;19.99&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="15" align="right" style="height: 15.0pt;"&gt;16759&lt;/TD&gt;
&lt;TD align="right"&gt;80160655&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;05-Sep-15&lt;/TD&gt;
&lt;TD align="right"&gt;19.99&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="15" align="right" style="height: 15.0pt;"&gt;16759&lt;/TD&gt;
&lt;TD align="right"&gt;80191135&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;06-Sep-15&lt;/TD&gt;
&lt;TD align="right"&gt;19.99&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="15" align="right" style="height: 15.0pt;"&gt;16759&lt;/TD&gt;
&lt;TD align="right"&gt;80191307&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;06-Sep-15&lt;/TD&gt;
&lt;TD align="right"&gt;19.99&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would it be easier if I skip the the transaction_date?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 22:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233923#M42735</guid>
      <dc:creator>SASEnthusiast</dc:creator>
      <dc:date>2015-11-09T22:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233924#M42736</link>
      <description>Sort of. I would consider simply marking any purchase that was 2 a negative (mulitply by negative 1) and then sum by ID. THat would give total purchase by user...not sure that's what you're after though.</description>
      <pubDate>Mon, 09 Nov 2015 22:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233924#M42736</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-09T22:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233967#M42752</link>
      <description>&lt;P&gt;Here could be solution using Hash:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
infile cards dlm='09'x truncover;
input (Customer_Id	Transaction_No)	(:$20.) Transaction_Date :anydtdte20.	Amount	Sales_Credit ;
format Transaction_Date date9.;
cards;
4699	80902288	22-Sep-15	55.3	2
4699	80686478	12-Sep-15	62.3	1
4699	80687203	12-Sep-15	55.3	1
4919	81735223	12-Oct-15	15.99	2
4919	80917293	22-Sep-15	15.99	1
4919	80917294	22-Sep-15	15.99	1
4919	80938352	22-Sep-15	23.99	1
6320	80926085	23-Sep-15	51.75	2
6320	80517713	09-Sep-15	51.75	1
6320	80512633	09-Sep-15	51.75	1
;

data want;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;dcl hash h(dataset:'have(drop=Transaction_No rename=(Transaction_Date=_date Sales_Credit=_credit) where=(_Credit=2))', multidata&amp;amp;colon;'y');&lt;BR /&gt;h.definekey('customer_id', 'amount');&lt;BR /&gt;h.definedata(all: 'y');&lt;BR /&gt;h.definedone();&lt;BR /&gt;call missing (_credit, _date);&lt;BR /&gt;end;&lt;BR /&gt;set have(where=(Sales_Credit=1));&lt;BR /&gt;if h.find()=0 and _date &amp;gt;= Transaction_Date then do;&lt;BR /&gt;h.removedup();&lt;BR /&gt;delete;&lt;BR /&gt;end;&lt;BR /&gt;drop _:;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 03:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233967#M42752</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-11-10T03:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233972#M42753</link>
      <description>&lt;P&gt;This works great!! Thank you so much.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 05:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233972#M42753</guid>
      <dc:creator>SASEnthusiast</dc:creator>
      <dc:date>2015-11-10T05:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233977#M42755</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The two things I would change in your code:&lt;/P&gt;
&lt;P&gt;- A keep statement for the data set loaded into the hash so that you're sure not to load variables you don't want to load&lt;/P&gt;
&lt;P&gt;- Loop over the "duplicates" in the hash and chose the oldest date where "_date &amp;gt;= Transaction_Date" is true. You can't be sure that the first match is the correct one, and it could also be possible that the condition is true for more than one return.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 08:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/233977#M42755</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-10T08:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/234042#M42771</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo&lt;/a&gt;&lt;/P&gt;&lt;P&gt;The two things I would change in your code:&lt;/P&gt;&lt;P&gt;- A keep statement for the data set loaded into the hash so that you're sure not to load variables you don't want to load&lt;/P&gt;&lt;P&gt;- Loop over the "duplicates" in the hash and chose the oldest date where "_date &amp;gt;= Transaction_Date" is true. You can't be sure that the first match is the correct one, and it could also be possible that the condition is true for more than one return.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;/P&gt;&lt;P&gt;1. Absolutely Agreed.&lt;/P&gt;&lt;P&gt;2. Not so sure about that. Customer behaves randomly, your suggestion is based on the assumption that 'first in - first out', which is not always&amp;nbsp;necessarily the case. Without more information&amp;nbsp; to identify the paired transactions,&amp;nbsp;this is as far as I would go.&amp;nbsp;But I do believe&amp;nbsp; you have raised a valid point to OP.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 15:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/234042#M42771</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-11-10T15:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/234156#M42801</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I believe if you don't select the earliest return date which satifies condition&amp;nbsp;&lt;SPAN&gt;"_date &amp;gt;= Transaction_Date" then you are at risk to miss some returns. Consider the following:&lt;/SPAN&gt;&lt;/P&gt;
&lt;TABLE width="434"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Rec_No&lt;/TD&gt;
&lt;TD width="89"&gt;Customer_Id&lt;/TD&gt;
&lt;TD width="120"&gt;Transaction_Date&lt;/TD&gt;
&lt;TD width="64"&gt;Amount&lt;/TD&gt;
&lt;TD width="97"&gt;Sales_Credit&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1-Nov-15&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;2-Nov-15&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;3-Nov-15&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;4-Nov-15&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use record 4 to remove record 1 then the pair record 2/record 3 won't satisfy condition&amp;nbsp;&lt;SPAN&gt;"_date &amp;gt;= Transaction_Date" and you'll miss the removal of record 3.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2015 08:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/234156#M42801</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-11T08:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a by variable group on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/234212#M42814</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I believe if you don't select the earliest return date which satifies condition&amp;nbsp;&lt;SPAN&gt;"_date &amp;gt;= Transaction_Date" then you are at risk to miss some returns. Consider the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Rec_No&lt;/TD&gt;&lt;TD&gt;Customer_Id&lt;/TD&gt;&lt;TD&gt;Transaction_Date&lt;/TD&gt;&lt;TD&gt;Amount&lt;/TD&gt;&lt;TD&gt;Sales_Credit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1-Nov-15&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2-Nov-15&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3-Nov-15&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4-Nov-15&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you use record 4 to remove record 1 then the pair record 2/record 3 won't satisfy condition&amp;nbsp;&lt;SPAN&gt;"_date &amp;gt;= Transaction_Date" and you'll miss the removal of record 3.&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for your following up and your point is well taken. However, if OP unfortunately&amp;nbsp;has data like that, the problem is beyond a simple code fix. Surely you will have your 'balance sheet', but you will never&amp;nbsp;know if paired transations are the actual pairs without more information. If the purpose is just to get the net 'balance', then the condition of '&lt;SPAN&gt;_date &amp;gt;= Transaction_Date' can be completely ignored. Given the data as is, my approach is to get as far as the 'known' can stand, and stop right at the point where 'unknown' starts.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Just my 2cents,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Haikuo&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2015 15:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-by-variable-group-on-condition/m-p/234212#M42814</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-11-11T15:57:20Z</dc:date>
    </item>
  </channel>
</rss>

