<?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: Looking for exact and partial matches in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230665#M41871</link>
    <description>This is great - Thank you so much. I liked the Sql soln and it did exactly what I wanted but I want to learn an equivalent SAS soln and here it is. Thanks again.</description>
    <pubDate>Tue, 20 Oct 2015 02:31:41 GMT</pubDate>
    <dc:creator>carmo</dc:creator>
    <dc:date>2015-10-20T02:31:41Z</dc:date>
    <item>
      <title>Looking for exact and partial matches</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230653#M41862</link>
      <description>&lt;P&gt;&lt;FONT face="HelevticaNeue-light, Helvetica Neue, Helvetica, Arial, sans-serif" color="#333333"&gt;&lt;SPAN&gt;Hello&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="HelevticaNeue-light, Helvetica Neue, Helvetica, Arial, sans-serif" color="#333333"&gt;&lt;SPAN&gt;I have been using SAS for years but I am a basic programmer and generally keep it simple but I want to get better. I have this situation that I can use the following code but I would like it to be smarter. In this scenario the max n is 3 but it could be as many as 50 and I don't want to write out the code. &amp;nbsp;So if anyone out there can educate/enlighten me I&amp;nbsp;would&amp;nbsp;be very&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;grateful&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA checking;&lt;BR /&gt;INPUT CUSTOMER_ACCOUNT_ID n sum_accounts ;&lt;BR /&gt;CARDS;&lt;BR /&gt;260 1 10436965&lt;BR /&gt;260 2 10436965&lt;BR /&gt;9629 1 9629&lt;BR /&gt;9629 2 88532203&lt;BR /&gt;15191 1 15191&lt;BR /&gt;15191 2 15191&lt;BR /&gt;15191 3 15191&lt;BR /&gt;17712 1 17712&lt;BR /&gt;17712 2 43811252&lt;BR /&gt;17712 3 17712&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data = checking out = x_checking (drop = _name_) prefix = count_;&lt;BR /&gt;by customer_account_id ;&lt;BR /&gt;id n;&lt;BR /&gt;var sum_accounts;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data x_checking_1;&lt;BR /&gt;set x_checking;&lt;/P&gt;&lt;P&gt;format match $10.;&lt;BR /&gt;if count_3 eq . then&lt;BR /&gt;do;&lt;BR /&gt;if count_1 = count_2 then match = 'yes';&lt;BR /&gt;else match = 'no';&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;else&lt;BR /&gt;do;&lt;BR /&gt;if count_1 = count_2 = count_3 then match = 'yes';&lt;BR /&gt;else if count_1 = count_2 or count_1 = count_3 or count_2 = count_3 then match = 'partial';&lt;BR /&gt;else match = 'no';&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 22:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230653#M41862</guid>
      <dc:creator>carmo</dc:creator>
      <dc:date>2015-10-19T22:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for exact and partial matches</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230657#M41864</link>
      <description>&lt;P&gt;One way to go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as
    select 
      CUSTOMER_ACCOUNT_ID, 
      count(*) as n_rows_per_CA, 
      count(distinct sum_accounts) as n_dif_vals_per_CA,
      case
        when calculated n_dif_vals_per_CA = 1 then 'yes'
        when calculated n_rows_per_CA = calculated n_dif_vals_per_CA then 'no'
        else 'partial'
        end as match length=7
    from checking
    group by CUSTOMER_ACCOUNT_ID
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Oct 2015 23:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230657#M41864</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-19T23:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for exact and partial matches</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230659#M41865</link>
      <description>&lt;P&gt;My take on this...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA checking;
INPUT ID n sum_a ;
CARDS;
260 1 10436965
260 2 10436965
9629 1 9629
9629 2 88532203
15191 1 15191
15191 2 15191
15191 3 15191
17712 1 17712
17712 2 43811252
17712 3 17712
;

proc sql;
create table matches as
select ID, 
    case
        when max(count) &amp;gt;= 2 and max(count) = sum(count) then "yes"
        when max(count) &amp;gt;= 2 then "partial"
        else "no"
        end as match
from (
    select ID, sum_a, count(sum_a) as count
    from checking
    group by ID, sum_a)
group by ID;
select * from matches;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Oct 2015 01:25:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230659#M41865</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-20T01:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for exact and partial matches</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230663#M41869</link>
      <description>&lt;P&gt;A possibility:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=checking;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by customer_account sum_accounts;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data checking;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;length match $ 10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;match='no';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do until (last.customer_account);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set checking;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; by customer_account sum_accounts;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if first.customer_account then&amp;nbsp;first_amount = sum_accounts;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if first.sum_accounts=0 then match='partial';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if last.customer_account and sum_accounts=first_amount then match='yes';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do until (last.customer_account);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set checking;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; by customer_account;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;drop first_amount;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then run the same PROC TRANSPOSE, adding in MATCH.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 02:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230663#M41869</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-20T02:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for exact and partial matches</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230664#M41870</link>
      <description>That is great thanks - simple and effective. Thanks very much&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Oct 2015 02:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230664#M41870</guid>
      <dc:creator>carmo</dc:creator>
      <dc:date>2015-10-20T02:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for exact and partial matches</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230665#M41871</link>
      <description>This is great - Thank you so much. I liked the Sql soln and it did exactly what I wanted but I want to learn an equivalent SAS soln and here it is. Thanks again.</description>
      <pubDate>Tue, 20 Oct 2015 02:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230665#M41871</guid>
      <dc:creator>carmo</dc:creator>
      <dc:date>2015-10-20T02:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for exact and partial matches</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230666#M41872</link>
      <description>Thanks a million for taking time to respond. Cheers</description>
      <pubDate>Tue, 20 Oct 2015 02:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230666#M41872</guid>
      <dc:creator>carmo</dc:creator>
      <dc:date>2015-10-20T02:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for exact and partial matches</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230668#M41873</link>
      <description>&lt;P&gt;Here is a data step solution:&lt;/P&gt;&lt;PRE&gt;proc sort data=checking out=_ck;
	by CUSTOMER_ACCOUNT_id sum_accounts;
run;

data want;
	do _n_=1 by 1 until (last.CUSTOMER_ACCOUNT_ID);
		set _ck;
		by CUSTOMER_ACCOUNT_ID sum_accounts;
		_ct+first.sum_accounts;
	end;

	length match $ 7;

	if _ct = _n_ and _ct&amp;gt;1 then
		match='No';
	else if _ct &amp;lt; _n_ and _ct &amp;gt;1 then
		match ='Partial';
	else if _ct = 1 and _n_ &amp;gt;1 then
		match = 'Yes';
	else match ='N/A';
	_ct=.;
	keep CUSTOMER_ACCOUNT_ID match;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Oct 2015 03:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230668#M41873</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-10-20T03:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for exact and partial matches</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230858#M41932</link>
      <description>Thanks very much</description>
      <pubDate>Wed, 21 Oct 2015 02:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-for-exact-and-partial-matches/m-p/230858#M41932</guid>
      <dc:creator>carmo</dc:creator>
      <dc:date>2015-10-21T02:49:52Z</dc:date>
    </item>
  </channel>
</rss>

