<?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 Proc Sort and First.variable - uncertain how to eliminate unnecessary rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853885#M337491</link>
    <description>&lt;P&gt;&lt;BR /&gt;Hello Everyone:&lt;/P&gt;&lt;P&gt;Having issues with developing logic around rewarding customers who open new deposit accounts on the same day vs different days. Only one reward is provided per newly opened account.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Scenario........&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have:&lt;/P&gt;&lt;P&gt;If customer A and customer B open a jointly held deposit account on Day 1 and&lt;BR /&gt;customer B and customer C open a joint account on Day 1 and&lt;BR /&gt;customer A and customer C open a joint account on Day 1 then reward customers A, B, C&amp;nbsp; &amp;nbsp; (3 rewards paid out)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If customer D and customer E open a joint account: reward either customer D or E&amp;nbsp; &amp;nbsp; (1 reward paid out)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If customer I and customer J and customer K open a joint account: reward either customer I or J or K&amp;nbsp; &amp;nbsp; (1 reward paid out)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;However;&lt;BR /&gt;If customer F and customer G open a jointly held deposit account on Day 1 and&lt;BR /&gt;customer G and customer H open a joint account on Day 2 and&lt;BR /&gt;customer F and customer H open a joint account on Day 3 then reward customers F or G.&amp;nbsp; &amp;nbsp; (1 reward paid out)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;(spaces added to datalines below to help clarify above groups)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile datalines truncover;&lt;BR /&gt;input customer_no $&amp;nbsp; &amp;nbsp;acctno $&amp;nbsp; &amp;nbsp;open_date;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;A 999 20221201&lt;BR /&gt;B 999 20221201&lt;BR /&gt;B 888 20221201&lt;BR /&gt;C 888 20221201&lt;BR /&gt;A 777 20221201&lt;BR /&gt;C 777 20221201&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;D 666 20221201&lt;BR /&gt;E 666 20221201&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;F 555 20221205&lt;BR /&gt;G 555 20221205&lt;BR /&gt;G 444 20221206&lt;BR /&gt;H 444 20221206&lt;BR /&gt;F 333 20221207&lt;BR /&gt;H 333 20221207&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I 222 20221209&lt;BR /&gt;J 222 20221209&lt;BR /&gt;K 222 20221209&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc print data=have;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; title 'have';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=have&amp;nbsp; &amp;nbsp; &amp;nbsp;out=temp2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; by customer_no&amp;nbsp; &amp;nbsp; &amp;nbsp;open_date;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=temp2(obs=40);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; title 'temp2';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp3;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set temp2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;by customer_no open_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if first.customer_no;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;proc print data=temp3(obs=40);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; title 'temp3';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;P&gt;A 999 20221201&lt;BR /&gt;B 888 20221201&lt;BR /&gt;C 777 20221201&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;D 666 20221201&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;F 555 20221205&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I 222 20221209&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So in the proc print table for dataset 'temp3'; below customers A,B,C,D,F, I are fine. However, I do not want customers E,G,H,J,K. I'm stuck at this point and at a loss how to eliminate those records.&lt;/P&gt;&lt;PRE&gt;data have;
	infile datalines truncover;
    input customer_no $  acctno $ open_date;

datalines;
A 999 20221201
B 999 20221201
B 888 20221201
C 888 20221201
A 777 20221201
C 777 20221201
D 666 20221201
E 666 20221201
F 555 20221205
G 555 20221205
G 444 20221206
H 444 20221206
F 333 20221207
H 333 20221207
I 222 20221209
J 222 20221209
K 222 20221209
;

proc print data=have;
	title 'have';
run;

proc sort data=have  out=temp2;
	by customer_no    open_date;
run;
proc print data=temp2(obs=40);
	title 'temp2';
	
run;

data temp3;
	set temp2;
		by customer_no   open_date;

		if first.customer_no;

run;
proc print data=temp3(obs=40);
	title 'temp3';
run;

/* WANT
A 999 20221201
B 888 20221201
C 777 20221201

D 666 20221201

F 555 20221205

I 222 20221209
*/&lt;/PRE&gt;&lt;P&gt;Many thanks for your assistance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sasasauraus_0-1673728937366.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79407i842F7A1D90A94525/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sasasauraus_0-1673728937366.png" alt="sasasauraus_0-1673728937366.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 14 Jan 2023 20:50:17 GMT</pubDate>
    <dc:creator>sasasauraus</dc:creator>
    <dc:date>2023-01-14T20:50:17Z</dc:date>
    <item>
      <title>Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853885#M337491</link>
      <description>&lt;P&gt;&lt;BR /&gt;Hello Everyone:&lt;/P&gt;&lt;P&gt;Having issues with developing logic around rewarding customers who open new deposit accounts on the same day vs different days. Only one reward is provided per newly opened account.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Scenario........&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have:&lt;/P&gt;&lt;P&gt;If customer A and customer B open a jointly held deposit account on Day 1 and&lt;BR /&gt;customer B and customer C open a joint account on Day 1 and&lt;BR /&gt;customer A and customer C open a joint account on Day 1 then reward customers A, B, C&amp;nbsp; &amp;nbsp; (3 rewards paid out)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If customer D and customer E open a joint account: reward either customer D or E&amp;nbsp; &amp;nbsp; (1 reward paid out)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If customer I and customer J and customer K open a joint account: reward either customer I or J or K&amp;nbsp; &amp;nbsp; (1 reward paid out)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;However;&lt;BR /&gt;If customer F and customer G open a jointly held deposit account on Day 1 and&lt;BR /&gt;customer G and customer H open a joint account on Day 2 and&lt;BR /&gt;customer F and customer H open a joint account on Day 3 then reward customers F or G.&amp;nbsp; &amp;nbsp; (1 reward paid out)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;(spaces added to datalines below to help clarify above groups)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile datalines truncover;&lt;BR /&gt;input customer_no $&amp;nbsp; &amp;nbsp;acctno $&amp;nbsp; &amp;nbsp;open_date;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;A 999 20221201&lt;BR /&gt;B 999 20221201&lt;BR /&gt;B 888 20221201&lt;BR /&gt;C 888 20221201&lt;BR /&gt;A 777 20221201&lt;BR /&gt;C 777 20221201&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;D 666 20221201&lt;BR /&gt;E 666 20221201&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;F 555 20221205&lt;BR /&gt;G 555 20221205&lt;BR /&gt;G 444 20221206&lt;BR /&gt;H 444 20221206&lt;BR /&gt;F 333 20221207&lt;BR /&gt;H 333 20221207&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I 222 20221209&lt;BR /&gt;J 222 20221209&lt;BR /&gt;K 222 20221209&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc print data=have;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; title 'have';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=have&amp;nbsp; &amp;nbsp; &amp;nbsp;out=temp2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; by customer_no&amp;nbsp; &amp;nbsp; &amp;nbsp;open_date;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=temp2(obs=40);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; title 'temp2';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp3;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set temp2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;by customer_no open_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if first.customer_no;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;proc print data=temp3(obs=40);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; title 'temp3';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;P&gt;A 999 20221201&lt;BR /&gt;B 888 20221201&lt;BR /&gt;C 777 20221201&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;D 666 20221201&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;F 555 20221205&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I 222 20221209&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So in the proc print table for dataset 'temp3'; below customers A,B,C,D,F, I are fine. However, I do not want customers E,G,H,J,K. I'm stuck at this point and at a loss how to eliminate those records.&lt;/P&gt;&lt;PRE&gt;data have;
	infile datalines truncover;
    input customer_no $  acctno $ open_date;

datalines;
A 999 20221201
B 999 20221201
B 888 20221201
C 888 20221201
A 777 20221201
C 777 20221201
D 666 20221201
E 666 20221201
F 555 20221205
G 555 20221205
G 444 20221206
H 444 20221206
F 333 20221207
H 333 20221207
I 222 20221209
J 222 20221209
K 222 20221209
;

proc print data=have;
	title 'have';
run;

proc sort data=have  out=temp2;
	by customer_no    open_date;
run;
proc print data=temp2(obs=40);
	title 'temp2';
	
run;

data temp3;
	set temp2;
		by customer_no   open_date;

		if first.customer_no;

run;
proc print data=temp3(obs=40);
	title 'temp3';
run;

/* WANT
A 999 20221201
B 888 20221201
C 777 20221201

D 666 20221201

F 555 20221205

I 222 20221209
*/&lt;/PRE&gt;&lt;P&gt;Many thanks for your assistance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sasasauraus_0-1673728937366.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79407i842F7A1D90A94525/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sasasauraus_0-1673728937366.png" alt="sasasauraus_0-1673728937366.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 20:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853885#M337491</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2023-01-14T20:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853886#M337492</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class="1673740468506"&gt;Hi,&lt;/P&gt;
&lt;P class="1673740468506"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="1673740468506"&gt;I don't understand the last group:&lt;/P&gt;
&lt;P class="1673740468506"&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class="1673740468506"&gt;&lt;SPAN&gt;If customer F and customer G open a jointly held deposit account on Day 1 and&lt;/SPAN&gt;&lt;/P&gt;
customer G and customer H open a joint account on Day 2 and&lt;BR /&gt;customer F and customer H open a joint account on Day 3 then reward customers F or G.&amp;nbsp; &amp;nbsp; (1 reward paid out)&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So if these three accounts were all opened on the same day, you would pay out 3 rewards (which is the first group).&amp;nbsp; But when they are opened on different days, you only pay 1 reward?&amp;nbsp; What happens if there is a gap in dates, e.g. F and G open a join account on Jan 1, then G and H open a join account on Jun 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can understand a rule "each account only triggers one reward, and no customer gets two rewards."&amp;nbsp; But the date part is hurting my head.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 23:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853886#M337492</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-01-14T23:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853889#M337494</link>
      <description>Yes this logic hurts my head too. In any respect; the campaign involves (new) FIRST deposit accounts for the customers. If the account is opened on Jan 1st by customers F &amp;amp; G (their first new account) then any subsequent account openings on later days or weeks or months are disqualified. Only if multiple accounts are opened on the SAME day do they (accounts) qualify. In your example above; the account opened by G and H on Jun 1 is disqualified because it is not their first newly opened account (their first new account was opened previously on Jan 1).</description>
      <pubDate>Sun, 15 Jan 2023 00:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853889#M337494</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2023-01-15T00:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853893#M337497</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355588"&gt;@sasasauraus&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes this logic hurts my head too. In any respect; the campaign involves (new) FIRST deposit accounts for the customers. If the account is opened on Jan 1st by customers F &amp;amp; G (their first new account) then any subsequent account openings on later days or weeks or months are disqualified. Only if multiple accounts are opened on the SAME day do they (accounts) qualify. In your example above; the account opened by G and H on Jun 1 is disqualified because it is not their first newly opened account (their first new account was opened previously on Jan 1).&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What if for a joint account customer A already got an earlier account opening but customer B is new? Does that disqualify the account?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your WANT data includes the customer. For a joint account that qualifies: Any logic which customer gets the reward?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a customer opens two accounts on the same day (FIRST deposit) you state that both accounts qualify: Does this mean the customer gets two rewards?&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 01:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853893#M337497</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-15T01:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853894#M337498</link>
      <description>&lt;P&gt;What if for a joint account customer A already got an earlier account opening but customer B is new? Does that disqualify the account?&amp;nbsp; Correct.&amp;nbsp; The latter account no longer qualifies as it is now the 2nd opened account.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your WANT data includes the customer. For a joint account that qualifies: Any logic which customer gets the reward?&lt;/P&gt;&lt;P&gt;Only one payout per opened account will qualify regardless of how many joint holders are on that particular account.&amp;nbsp; Does not matter who gets the reward per account.&amp;nbsp; Customers should not be rewarded multiple times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If a customer opens two accounts on the same day (FIRST deposit) you state that both accounts qualify: Does this mean the customer gets two rewards?&amp;nbsp; No; this is considered a single held account not joint.&amp;nbsp; If A&amp;nbsp; opens acct #111 and A&amp;nbsp; opens acct# 222 on the same day then A is rewarded once.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 02:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853894#M337498</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2023-01-15T02:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853896#M337500</link>
      <description>&lt;P&gt;Adding notes to help clarify matters further:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* WANT */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A 999 20221201&lt;BR /&gt;B 888 20221201&lt;BR /&gt;C 777 20221201&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;D or E&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 666 20221201&lt;/P&gt;&lt;P&gt;F or G&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 555 20221205&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I or J or K&amp;nbsp; &amp;nbsp; 222 20221209&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Notes as per above WANT:&lt;BR /&gt;Acct#&amp;nbsp; &amp;nbsp;555&amp;nbsp; &amp;nbsp;(F or G qualifies as this is their 1st account - but only 1 customer will be rewarded)&lt;/P&gt;&lt;P&gt;Acct#&amp;nbsp; &amp;nbsp;666&amp;nbsp; (D or E qualifies as this is their 1st account - but only 1 customer will be rewarded)&lt;/P&gt;&lt;P&gt;Acct#&amp;nbsp; &amp;nbsp;222&amp;nbsp; (I or J or K qualifies as this is their 1st account - but only 1 customer will be rewarded)&lt;/P&gt;&lt;P&gt;*****************************************************&lt;/P&gt;&lt;P&gt;F 555 20221205&amp;nbsp;&lt;BR /&gt;G 555 20221205&amp;nbsp;&lt;BR /&gt;G 444 20221206&amp;nbsp; &amp;nbsp;(disqualified as 1st account opened 2022-12-05)&lt;BR /&gt;H 444 20221206&amp;nbsp; &amp;nbsp;(disqualified as joint customer G's 1st account opened 2022-12-05)&lt;BR /&gt;F 333 20221207&amp;nbsp; &amp;nbsp;(disqualified as 1st account opened 2022-12-05)&lt;BR /&gt;H 333 20221207&amp;nbsp;&amp;nbsp;(disqualified as joint customer F's 1st account opened 2022-12-05)&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 03:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853896#M337500</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2023-01-15T03:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853923#M337510</link>
      <description>Hi:&lt;BR /&gt;  These "rules" seem to penalize person H for even having a joint account. It seems like if H had set up a single account on 12/6 and ditched G, they would have gotten the award. These rules seem erratic.&lt;BR /&gt;Cynthia</description>
      <pubDate>Sun, 15 Jan 2023 14:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853923#M337510</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2023-01-15T14:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853925#M337512</link>
      <description>&lt;P&gt;I'm still struggling with defining the rule. &amp;nbsp;Is it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A new account triggers a reward (for one of the account owners) &lt;EM&gt;unless&lt;/EM&gt; one of the account owners for the new account is also an owner of an account the previously triggered a reward. &amp;nbsp;(Previously means an account opened on an earlier date).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 15:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853925#M337512</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-01-15T15:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853926#M337513</link>
      <description>&lt;P&gt;Yes, that is correct.&amp;nbsp; Essentially; if customer(s) open any subsequent account(s) any time afterwards, then these records can be tossed out.&amp;nbsp; Only the very first open accounts are in consideration for reward.&amp;nbsp; My earlier example:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer&amp;nbsp; Account&amp;nbsp; Open_Date&lt;/P&gt;&lt;P&gt;------------&amp;nbsp; &amp;nbsp; ----------&amp;nbsp; &amp;nbsp;--------------&lt;/P&gt;&lt;P&gt;F&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;555&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20221205 (F or G qualifies as this is their 1st account - reward F or G but not both)&lt;BR /&gt;G&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 555&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20221205 (F or G qualifies as this is their 1st account - reward F or G but not both)&lt;/P&gt;&lt;P&gt;G&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 444&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20221206 (does not qualify as G opened a previous acct on 2022105)&lt;BR /&gt;H&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 444&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20221206 (does not qualify as joint owner G opened a previous acct on 2022105)&lt;BR /&gt;F&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20221207 (does not qualify as F opened a previous acct on 2022105)&lt;BR /&gt;H&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20221207 (does not qualify as H opened a previous acct on 2022106 with G who opened a previous account on 20221205)&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 16:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853926#M337513</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2023-01-15T16:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853930#M337515</link>
      <description>&lt;P&gt;I think I would approach this with a hash table. I don't have time to try coding it, but I think would approach like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Sort the data by Open_Date Account Customer&lt;/LI&gt;
&lt;LI&gt;Read in the data in a DATA step (probably DOW loop) set by Open_Date Account Customer&lt;/LI&gt;
&lt;LI&gt;Create a hash table that will hold the Customer IDs of all customers that are co-owners of an account that has triggered a reward. &amp;nbsp;The hashtable will have Customer and OpenDate. &amp;nbsp;The hash table starts empty.&lt;/LI&gt;
&lt;LI&gt;Read in the customers for the first account by-group.&lt;/LI&gt;
&lt;LI&gt;Check each customer for the account, to see if it exists in the hash table, with an open date in the hash table that is earlier that the current account's open date.&lt;/LI&gt;
&lt;LI&gt;After reading through all the customers for the account, if none of them were already in the hash table with an earlier open date:
&lt;OL&gt;
&lt;LI&gt;This account triggers a reward&lt;/LI&gt;
&lt;LI&gt;Add all the customers for this account to the hash table (with the open date for this account)&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I think that might do it. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: I don't think the above handles a case where A opens two accounts on the same day. &amp;nbsp;It would give them double rewards. &amp;nbsp;Perhaps that could be de-duped in a separate step. &amp;nbsp;What happens if A opens an account on day 1 and &amp;nbsp;also on day 1 A and B open an account. &amp;nbsp;Does B get a reward? &amp;nbsp;Above algorithm would say this account generates an award. &amp;nbsp;But would need another step to determine that the award goes to B. &amp;nbsp;Perhaps the above step would be useful for generating all the accounts that trigger rewards. &amp;nbsp;Then a separate step could be used to dedup and determine who gets the reward from each account. &amp;nbsp;This is tricky. : )&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 16:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/853930#M337515</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-01-15T16:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/854010#M337545</link>
      <description>&lt;P&gt;Thanks Quentin.&amp;nbsp; I do not have familiarity with hash tables as I am a novice SAS user.&amp;nbsp; Nevertheless; I will give your advice a shot.&amp;nbsp; Also; to answer your question....yes, B would also get a reward as we have two accounts opened on the same day.&amp;nbsp; One reward per account opened on the same day but do not reward the same customer twice.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 18:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/854010#M337545</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2023-01-16T18:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/856738#M338500</link>
      <description>Thank you everyone who laid eyes on this dilemma of mine. Special thanks to Quentin (the Proc Star) who provided a segway into a solution. Also; I need to praise a co-worker who took Quentin's option and ran with it. With intestinal fortitude and immense tenacity she managed to pull together Hash table code worth its weight in gold; thus saving my bacon. Just need to figure how to upload the solution....please stay tuned.</description>
      <pubDate>Wed, 01 Feb 2023 20:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/856738#M338500</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2023-02-01T20:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort and First.variable - uncertain how to eliminate unnecessary rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/856739#M338501</link>
      <description>&lt;BR /&gt;%macro printme(in1);&lt;BR /&gt;proc print data=&amp;amp;in1(obs=50);&lt;BR /&gt;title "%upcase(&amp;amp;in1)";&lt;BR /&gt;run;&lt;BR /&gt;proc contents data=&amp;amp;in1;&lt;BR /&gt;title "%upcase(&amp;amp;in1)";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%mend printme;&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile datalines truncover;&lt;BR /&gt;input customer_no $ acctno $ open_date;&lt;BR /&gt;&lt;BR /&gt;datalines;&lt;BR /&gt;A 999 20221201&lt;BR /&gt;B 999 20221201&lt;BR /&gt;B 888 20221201&lt;BR /&gt;C 888 20221201&lt;BR /&gt;A 777 20221201&lt;BR /&gt;C 777 20221201&lt;BR /&gt;D 666 20221201&lt;BR /&gt;E 666 20221201&lt;BR /&gt;F 555 20221205&lt;BR /&gt;G 555 20221205&lt;BR /&gt;G 444 20221206&lt;BR /&gt;H 444 20221206&lt;BR /&gt;F 333 20221207&lt;BR /&gt;H 333 20221207&lt;BR /&gt;I 222 20221209&lt;BR /&gt;J 222 20221209&lt;BR /&gt;K 222 20221209&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table tble1_1 as&lt;BR /&gt;select distinct&lt;BR /&gt;h1.open_date&lt;BR /&gt;, h1.acctno&lt;BR /&gt;, h1.customer_no&lt;BR /&gt;, h2.open_date as h2_open_date&lt;BR /&gt;&lt;BR /&gt;from have h1&lt;BR /&gt;left join&lt;BR /&gt;have h2&lt;BR /&gt;on h1.customer_no = h2.customer_no&lt;BR /&gt;&lt;BR /&gt;order by h1.open_date, h2.open_date desc, h1.acctno, h1.customer_no&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;%printme(tble1_1);&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table tble1_base as&lt;BR /&gt;select&lt;BR /&gt;open_date&lt;BR /&gt;, acctno&lt;BR /&gt;, customer_no&lt;BR /&gt;, min(h2_open_date) As cust_acct_min_open_dt&lt;BR /&gt;&lt;BR /&gt;from tble1_1&lt;BR /&gt;&lt;BR /&gt;group by&lt;BR /&gt;open_date&lt;BR /&gt;, acctno&lt;BR /&gt;, customer_no&lt;BR /&gt;&lt;BR /&gt;order by open_date, acctno, customer_no desc&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;%printme(tble1_base);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table tble1_acctno as&lt;BR /&gt;select&lt;BR /&gt;acctno&lt;BR /&gt;, min(h2_open_date) As acct_min_open_dt&lt;BR /&gt;&lt;BR /&gt;from tble1_1&lt;BR /&gt;&lt;BR /&gt;group by acctno&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;%printme(tble1_acctno);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table tble1_customer as&lt;BR /&gt;select&lt;BR /&gt;customer_no&lt;BR /&gt;, min(open_date) As cust_min_open_dt&lt;BR /&gt;&lt;BR /&gt;from tble1_1&lt;BR /&gt;group by customer_no&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;%printme(tble1_customer);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table tble1_2 As&lt;BR /&gt;select&lt;BR /&gt;base.open_date&lt;BR /&gt;, base.acctno&lt;BR /&gt;, base.customer_no&lt;BR /&gt;/* , base.cust_acct_min_open_dt*/&lt;BR /&gt;, acct.acct_min_open_dt&lt;BR /&gt;, cust.cust_min_open_dt&lt;BR /&gt;&lt;BR /&gt;from tble1_base base&lt;BR /&gt;&lt;BR /&gt;inner join tble1_acctno acct&lt;BR /&gt;on base.acctno = acct.acctno&lt;BR /&gt;&lt;BR /&gt;inner join tble1_customer cust&lt;BR /&gt;on base.customer_no = cust.customer_no&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;%printme(tble1_2);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;if _n_ = 1 then&lt;BR /&gt;do;&lt;BR /&gt;if 0 then set tble1_2; /* Add variables from the view */&lt;BR /&gt;&lt;BR /&gt;/* to the PDV for WORK.NEW */&lt;BR /&gt;declare hash ht(ordered: 'a');&lt;BR /&gt;ht.definekey ('open_date','acctno');&lt;BR /&gt;ht.definedata('open_date','acctno','customer_no','cust_min_open_dt','acct_min_open_dt','ind_candidate');&lt;BR /&gt;ht.definedone();&lt;BR /&gt;&lt;BR /&gt;declare hash custno();&lt;BR /&gt;custno.definekey('customer_no');&lt;BR /&gt;custno.definedone();&lt;BR /&gt;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;do while(not last);&lt;BR /&gt;set tble1_2 end=last;&lt;BR /&gt;&lt;BR /&gt;open_date = open_date;&lt;BR /&gt;acctno = acctno;&lt;BR /&gt;/* customer_no = customer_no;*/&lt;BR /&gt;&lt;BR /&gt;if (open_date = cust_min_open_dt) and (open_date = acct_min_open_dt) then&lt;BR /&gt;do;&lt;BR /&gt;if ht.find() NE 0&lt;BR /&gt;and custno.find() NE 0 then&lt;BR /&gt;do;&lt;BR /&gt;ind_candidate=1;&lt;BR /&gt;rc1=ht.add();&lt;BR /&gt;&lt;BR /&gt;rc2=custno.add();&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;if last then&lt;BR /&gt;do;&lt;BR /&gt;ht.output(dataset:'want'); /* write data using HashSort */&lt;BR /&gt;custno.output(dataset:'clients');&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Feb 2023 20:35:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sort-and-First-variable-uncertain-how-to-eliminate/m-p/856739#M338501</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2023-02-01T20:35:52Z</dc:date>
    </item>
  </channel>
</rss>

