<?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: Matching clients with SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802336#M315851</link>
    <description>For some reason it is keeping the observation for the pen</description>
    <pubDate>Tue, 15 Mar 2022 20:16:32 GMT</pubDate>
    <dc:creator>macedonataan</dc:creator>
    <dc:date>2022-03-15T20:16:32Z</dc:date>
    <item>
      <title>Matching clients with SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802101#M315734</link>
      <description>&lt;P&gt;Hi guys, let's suppose the following scenario.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Clientid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Purchase_Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;item_name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;amount&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; book&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; book&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $-20&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03/01/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pen&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $2&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;04/01/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; game&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$70&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03/01/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pen&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $-2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;06/01/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bike&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is possible to see that there is some negative values under the [amount] column,&amp;nbsp;these refers to items returned to the store, and it's recorded as a negative purchase.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to know how could I remove transactions (both positive and negative) for&amp;nbsp; items that returned to the store?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Notes: The orders returned have the same [Clientid], [Purchase_Date], [item_name], and [amount]&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 06:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802101#M315734</guid>
      <dc:creator>macedonataan</dc:creator>
      <dc:date>2022-03-15T06:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Matching clients with SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802105#M315736</link>
      <description>&lt;P&gt;how about this&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Clientid Purchase_Date:mmddyy10. item_name $ amount:dollar4.;
format Purchase_Date mmddyy10.
       amount dollar4.;
datalines;
1 01/01/2020 book $20
1 01/01/2020 book $-20
2 03/01/2020 pen  $2
3 04/01/2020 game $70
2 03/01/2020 pen  $-2
1 06/01/2020 bike $200
;
run;

proc sql;
  create table want as
  select a.* from have as a
  left join have as b
  on a.Clientid=b.Clientid and 
     a.Purchase_Date=b.Purchase_Date and 
     a.item_name=b.item_name and
     a.amount=b.amount*(-1)
  where b.amount=.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Mar 2022 03:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802105#M315736</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-03-15T03:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: Matching clients with SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802110#M315740</link>
      <description>&lt;P&gt;A Data Step approach. Sort the data set. Remove the pair of observations that starts with negative AMOUNT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Clientid Purchase_Date:mmddyy10. item_name $ amount:dollar4.;
format Purchase_Date mmddyy10.
       amount dollar4.;
datalines;
1 01/01/2020 book $20
1 01/01/2020 book $-20
2 03/01/2020 pen  $2
3 04/01/2020 game $70
2 03/01/2020 pen  $-2
1 06/01/2020 bike $200
;
run;

proc sort data = have out = have_sorted;
	by Clientid Purchase_Date item_name amount;
run;

data want;
	do until(last.Clientid);
		set have_sorted;
		by Clientid;
		if amount &amp;lt; 0 then do; prev = 1; delete; end;
		else if amount &amp;gt;= 0 and prev = 1 then do; delete; prev = .; end;
	end;
drop prev;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Mar 2022 05:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802110#M315740</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2022-03-15T05:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Matching clients with SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802113#M315741</link>
      <description>&lt;P&gt;Put all the returns (amount&amp;lt;0) in a hash object.&amp;nbsp; &amp;nbsp;Read in all the purchases (amount&amp;gt;0), keeping only those for which there is no offsetting return.&amp;nbsp; This can be done without data sorting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Clientid Purchase_Date:mmddyy10. item_name $ amount:dollar4.;
format Purchase_Date mmddyy10.
       amount dollar4.;
datalines;
1 01/01/2020 book $20
1 01/01/2020 book $-20
2 03/01/2020 pen  $2
3 04/01/2020 game $70
2 03/01/2020 pen  $-2
1 06/01/2020 bike $200
;
run;
data want;
  set have (where=(amount&amp;gt;0));
  if _n_=1 then do;
    declare hash returns (dataset:'have (where=(amount&amp;lt;0))');
      returns.definekey(all:'Y');
      returns.definedata(all:'Y');
      returns.definedone();
  end;
  if returns.check(key:clientid,key:purchase_date,key:item_name,key:-1*amount)^=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This program assumes that no item is purchased more than once by a given client on a given date.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 05:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802113#M315741</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-15T05:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Matching clients with SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802120#M315748</link>
      <description>&lt;P&gt;Is there a way of doing it assuming the possibility of items being purchased more then once by the same client?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 06:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802120#M315748</guid>
      <dc:creator>macedonataan</dc:creator>
      <dc:date>2022-03-15T06:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Matching clients with SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802267#M315821</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/419530"&gt;@macedonataan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there a way of doing it assuming the possibility of items being purchased more then once by the same client?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"more than once by the same client", is ok but "more than once &lt;EM&gt;&lt;STRONG&gt;ON THE SAME DAY&lt;/STRONG&gt;&lt;/EM&gt;" would require revisions&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 16:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802267#M315821</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-15T16:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Matching clients with SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802336#M315851</link>
      <description>For some reason it is keeping the observation for the pen</description>
      <pubDate>Tue, 15 Mar 2022 20:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802336#M315851</guid>
      <dc:creator>macedonataan</dc:creator>
      <dc:date>2022-03-15T20:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Matching clients with SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802339#M315853</link>
      <description>It works perfectly for the didactic example, however when applied to real data (+10Mi rows) it seems to match more observations than it should....</description>
      <pubDate>Tue, 15 Mar 2022 20:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-clients-with-SAS/m-p/802339#M315853</guid>
      <dc:creator>macedonataan</dc:creator>
      <dc:date>2022-03-15T20:37:33Z</dc:date>
    </item>
  </channel>
</rss>

