<?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 Customer ownership table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Customer-ownership-table/m-p/821299#M324245</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;The "have" data set includes information about ownership structure of each customer in the bank.&lt;/P&gt;
&lt;P&gt;It includes the columns:&lt;/P&gt;
&lt;P&gt;Customer_number,ID_number,Wealth&lt;/P&gt;
&lt;P&gt;As can see each customer can have multiple rows If there are multiple ID's under customer .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a new dats set called "want" with the following columns:&lt;/P&gt;
&lt;P&gt;Customer_number&lt;/P&gt;
&lt;P&gt;Nr_ID&lt;/P&gt;
&lt;P&gt;Nr_Related_customers&lt;/P&gt;
&lt;P&gt;customer_wealth&lt;/P&gt;
&lt;P&gt;Total_Wealth_From_Related_Customers&lt;/P&gt;
&lt;P&gt;As can see each customer will have only one row in "want" data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nr_ID&amp;nbsp; be calculated by :count(*) as Nr_ID&lt;/P&gt;
&lt;P&gt;customer_wealth be calculated by :Max(Wealth) as Customer_Wealth&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question:&lt;/P&gt;
&lt;P&gt;What is the way to calculate columns:&lt;/P&gt;
&lt;P&gt;"Nr_Related_customers"&amp;nbsp; ,&lt;/P&gt;
&lt;P&gt;"Total_Wealth_From_Related_Customers"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;Customer_number 1:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are 2 ID's under customer 1:111,222&lt;/P&gt;
&lt;P&gt;ID 111 belongs also to another customer :2&lt;/P&gt;
&lt;P&gt;ID 222 belong also to another customer:3&lt;/P&gt;
&lt;P&gt;So there are total 3 customers whoch are related to customer 111&lt;/P&gt;
&lt;P&gt;and the total wealth of these 3 customers is 100+200+300=600&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;		
input  Customer_number   ID_number   Wealth;		
cards;		
1 111 100
1 222 100
2 111 200
3 222 300
4 333 400
5 444 500
5 555 500
;		
Run;		
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;				
input  Customer_number Nr_ID Nr_Related_customers customer_wealth Total_Wealth_From_Related_Customers;				
cards;				
1 2 3 100	600
2 1 2 200	300
3 1 2 300	400
4 1 1 400	400
5 2 1 500	500
;
Run;&lt;/CODE&gt;&lt;/PRE&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="Ronein_0-1656687573729.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72893i08E7A2CBA3EAE209/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1656687573729.png" alt="Ronein_0-1656687573729.png" /&gt;&lt;/span&gt;&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;
&lt;P&gt;&amp;nbsp;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Jul 2022 14:59:44 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2022-07-01T14:59:44Z</dc:date>
    <item>
      <title>Customer ownership table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Customer-ownership-table/m-p/821299#M324245</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;The "have" data set includes information about ownership structure of each customer in the bank.&lt;/P&gt;
&lt;P&gt;It includes the columns:&lt;/P&gt;
&lt;P&gt;Customer_number,ID_number,Wealth&lt;/P&gt;
&lt;P&gt;As can see each customer can have multiple rows If there are multiple ID's under customer .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a new dats set called "want" with the following columns:&lt;/P&gt;
&lt;P&gt;Customer_number&lt;/P&gt;
&lt;P&gt;Nr_ID&lt;/P&gt;
&lt;P&gt;Nr_Related_customers&lt;/P&gt;
&lt;P&gt;customer_wealth&lt;/P&gt;
&lt;P&gt;Total_Wealth_From_Related_Customers&lt;/P&gt;
&lt;P&gt;As can see each customer will have only one row in "want" data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nr_ID&amp;nbsp; be calculated by :count(*) as Nr_ID&lt;/P&gt;
&lt;P&gt;customer_wealth be calculated by :Max(Wealth) as Customer_Wealth&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question:&lt;/P&gt;
&lt;P&gt;What is the way to calculate columns:&lt;/P&gt;
&lt;P&gt;"Nr_Related_customers"&amp;nbsp; ,&lt;/P&gt;
&lt;P&gt;"Total_Wealth_From_Related_Customers"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;Customer_number 1:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are 2 ID's under customer 1:111,222&lt;/P&gt;
&lt;P&gt;ID 111 belongs also to another customer :2&lt;/P&gt;
&lt;P&gt;ID 222 belong also to another customer:3&lt;/P&gt;
&lt;P&gt;So there are total 3 customers whoch are related to customer 111&lt;/P&gt;
&lt;P&gt;and the total wealth of these 3 customers is 100+200+300=600&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;		
input  Customer_number   ID_number   Wealth;		
cards;		
1 111 100
1 222 100
2 111 200
3 222 300
4 333 400
5 444 500
5 555 500
;		
Run;		
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;				
input  Customer_number Nr_ID Nr_Related_customers customer_wealth Total_Wealth_From_Related_Customers;				
cards;				
1 2 3 100	600
2 1 2 200	300
3 1 2 300	400
4 1 1 400	400
5 2 1 500	500
;
Run;&lt;/CODE&gt;&lt;/PRE&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="Ronein_0-1656687573729.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72893i08E7A2CBA3EAE209/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1656687573729.png" alt="Ronein_0-1656687573729.png" /&gt;&lt;/span&gt;&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;
&lt;P&gt;&amp;nbsp;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2022 14:59:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Customer-ownership-table/m-p/821299#M324245</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-07-01T14:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Customer ownership table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Customer-ownership-table/m-p/821353#M324267</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;		
input  Customer_number   ID_number   Wealth;		
cards;		
1 111 100
1 222 100
2 111 200
3 222 300
4 333 400
5 444 500
5 555 500
;		
Run;

proc sql;
create table part1 as
select Customer_number,count(distinct ID_number) as Nr_ID 
 from have 
  group by Customer_number;

create table part2 as
select a.Customer_number,count(distinct b.Customer_number) as Nr_Related_customers 
 from have as a,have as b
  where a.ID_number=b.ID_number
   group by a.Customer_number;

create table part3 as
select distinct Customer_number,Wealth as customer_wealth 
 from have;

create table part4 as
select a.Customer_number,sum(b.customer_wealth) as Total_Wealth_From_Related_Custom
from
(
select distinct a.Customer_number, b.Customer_number as  _Customer_number
 from have as a,have as b
  where a.ID_number=b.ID_number
) as a left join part3 as b
on a._Customer_number=b.Customer_number
group by a.Customer_number;
quit;

data want;
 merge part1-part4;
 by Customer_number;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Jul 2022 07:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Customer-ownership-table/m-p/821353#M324267</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-07-02T07:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Customer ownership table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Customer-ownership-table/m-p/821354#M324268</link>
      <description>Thanks,&lt;BR /&gt;As I see the key here is to use  CARTESIAN JOIN</description>
      <pubDate>Sat, 02 Jul 2022 07:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Customer-ownership-table/m-p/821354#M324268</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-07-02T07:26:06Z</dc:date>
    </item>
  </channel>
</rss>

