<?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 Ownership of bank accounts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759263#M239901</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set that show the ownership of bank accounts.&lt;/P&gt;
&lt;P&gt;There are 2 columns:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Account- Key number of the bank account&lt;/P&gt;
&lt;P&gt;ID - Identification&amp;nbsp; number of the owner of the bank account&lt;/P&gt;
&lt;P&gt;My task is to classify each bank account into one of the following groups:&lt;/P&gt;
&lt;P&gt;1- Bank account has only one ownership and the ID doesn't appear in other bank accounts&lt;/P&gt;
&lt;P&gt;2- Bank account has only one ownership and the ID&amp;nbsp; appear in other bank accounts&lt;/P&gt;
&lt;P&gt;3-Bank account has more than one ID ownership and all ID's don't appear in other bank accounts.&lt;/P&gt;
&lt;P&gt;4-Bank account has more than one ID ownership and at least one&amp;nbsp; ID&amp;nbsp; appear in other bank accounts.&lt;/P&gt;
&lt;P&gt;May anyone show a code to do it please?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data rawtbl;
input account ID $ ;
cards;
111 X
111 Y
222 X
333 Y
444 Y
444 R
789 R
555 Q
666 V
666 T
777 A
888 A
999 A
999 B
123 B
;
Run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2-Bank account has more than one ownership and the ID's doesn't appear in other bank accounts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Aug 2021 10:11:08 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-08-04T10:11:08Z</dc:date>
    <item>
      <title>Ownership of bank accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759263#M239901</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set that show the ownership of bank accounts.&lt;/P&gt;
&lt;P&gt;There are 2 columns:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Account- Key number of the bank account&lt;/P&gt;
&lt;P&gt;ID - Identification&amp;nbsp; number of the owner of the bank account&lt;/P&gt;
&lt;P&gt;My task is to classify each bank account into one of the following groups:&lt;/P&gt;
&lt;P&gt;1- Bank account has only one ownership and the ID doesn't appear in other bank accounts&lt;/P&gt;
&lt;P&gt;2- Bank account has only one ownership and the ID&amp;nbsp; appear in other bank accounts&lt;/P&gt;
&lt;P&gt;3-Bank account has more than one ID ownership and all ID's don't appear in other bank accounts.&lt;/P&gt;
&lt;P&gt;4-Bank account has more than one ID ownership and at least one&amp;nbsp; ID&amp;nbsp; appear in other bank accounts.&lt;/P&gt;
&lt;P&gt;May anyone show a code to do it please?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data rawtbl;
input account ID $ ;
cards;
111 X
111 Y
222 X
333 Y
444 Y
444 R
789 R
555 Q
666 V
666 T
777 A
888 A
999 A
999 B
123 B
;
Run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2-Bank account has more than one ownership and the ID's doesn't appear in other bank accounts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 10:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759263#M239901</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-08-04T10:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Ownership of bank accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759269#M239905</link>
      <description>&lt;P&gt;&lt;STRONG&gt;PLEASE&lt;/STRONG&gt; do us a big, big favor and name your example datasets "have", like we all do; it is really painful to realize that you name it "rawtbl" when the code crashes on the first test run.&lt;/P&gt;
&lt;P&gt;First, create an intermediate table that contains all ID's and a flag for multiple usage:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table id as
  select
    id,
    case
      when count(*) gt 1
      then 1
      else 0
    end as id_mult
  from have
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Next, sort the have dataset by account:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by account;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so we can use BY in the final data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by account;
if _n_ = 1
then do;
  declare hash idm (dataset:"id");
  idm.definekey("id");
  idm.definedata("id_mult");
  idm.definedone();
  call missing(id_mult);
end;
retain mult_id;
if first.account then mult_id = 0;
rc = idm.find();
mult_id = max(mult_id,id_mult);
if last.account;
mult_acct = not first.account;
keep account mult_acct mult_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The intermediate table is loaded into a hash object for lookup.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 10:35:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759269#M239905</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-04T10:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Ownership of bank accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759270#M239906</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;PROC FREQ gives all the info you are looking for.&lt;/P&gt;
&lt;P&gt;Can you go on from there?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data rawtbl;
input account ID $ ;
cards;
111 X
111 Y
222 X
333 Y
444 Y
444 R
789 R
555 Q
666 V
666 T
777 A
888 A
999 A
999 B
123 B
;
run;

/*
1- Bank account has only one ownership and the ID doesn't appear in other bank accounts
2- Bank account has only one ownership and the ID  appear in other bank accounts
3- Bank account has more than one ID ownership and all ID's don't appear in other bank accounts.
4- Bank account has more than one ID ownership and at least one  ID  appear in other bank accounts.
*/
ods trace off;
ods output CrossTabFreqs=work.CrossTabFreqs;
PROC FREQ data=rawtbl noprint;
 tables account * ID / missing out=count_account_ID;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 10:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759270#M239906</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-08-04T10:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: Ownership of bank accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759275#M239909</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp;I feel you need to explain your line of thought a bit more. The OP basically asks for 4 flag variables. What you propose is the result of a proc freq that has the same number of rows than the source table. Not sure how that helps.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 11:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759275#M239909</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-04T11:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Ownership of bank accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759279#M239912</link>
      <description>&lt;P&gt;Hello&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should build upon the ODS output dataset.&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;ods output CrossTabFreqs=work.CrossTabFreqs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not solved this evening (after the work day) I will complete my program.&lt;/P&gt;
&lt;P&gt;I haven't thought it through for the full 100%, so I maybe wrong that all 4 flag-variables can be derived from CrossTabFreqs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 11:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759279#M239912</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-08-04T11:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Ownership of bank accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759282#M239915</link>
      <description>&lt;P&gt;Not sure what do you expect as result exactly, so i created a variable group having the values 1 to 4 to identify the groups you have defined.&lt;/P&gt;
&lt;P&gt;And i assumed, that the data is grouped by account.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Get number of accounts per ID */
proc summary data= work.rawtbl nway;
   class id;
   output out= work.Ids(drop= _type_ rename= (_freq_ = count));
run;

/* Using work.Ids as hash-object */
data want;
   if 0 then set work.Ids;

   set work.rawtbl;
   by account notsorted;

   length group 8 multiOwner multiAccount 8;
   retain multiAccount;

   if _n_ = 1 then do;
      declare hash owner(dataset: 'work.Ids');
      owner.defineKey('id');
      owner.defineData('count');
      owner.defineDone();
   end;

   if first.account then do;
      multiAccount = 1;
   end;

   multiOwner = not (first.account and last.account);
   rc = owner.find();
   multiAccount = multiAccount and (count &amp;gt; 1);

   if last.account then do;
      group = input(cats(multiOwner, multiAccount), binary2.) + 1;
      output;
   end;
   
   drop count rc id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Aug 2021 11:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ownership-of-bank-accounts/m-p/759282#M239915</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-04T11:25:23Z</dc:date>
    </item>
  </channel>
</rss>

