<?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: concatenate of customer accounts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797487#M313519</link>
    <description>I need concatenate distinct list of all customers that belong to the ID'S of each customer</description>
    <pubDate>Sun, 20 Feb 2022 18:55:19 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2022-02-20T18:55:19Z</dc:date>
    <item>
      <title>concatenate of customer accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797451#M287544</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have 2 data sets:&lt;/P&gt;
&lt;P&gt;1-Date Set Have1 have information of customer accounts that belong to each person ID.&lt;/P&gt;
&lt;P&gt;2-Data set Have2 have information of&amp;nbsp; people ID's that belong to each customer account.&lt;/P&gt;
&lt;P&gt;Please note that&amp;nbsp;&lt;CODE class=" language-sas"&gt;CAT_Customers is&amp;nbsp;concatenate&amp;nbsp;of&amp;nbsp;customer&amp;nbsp;accounts&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Please note that&amp;nbsp;&lt;CODE class=" language-sas"&gt;CAT_ID is&amp;nbsp;concatenate&amp;nbsp;of&amp;nbsp;people&amp;nbsp;ID&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;The&amp;nbsp;task&amp;nbsp;is&amp;nbsp;to&amp;nbsp;add&amp;nbsp;to&amp;nbsp;Have2&amp;nbsp;the&amp;nbsp;following&amp;nbsp;2&amp;nbsp;columns:&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;1-CAT_Customers&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;It&amp;nbsp;is&amp;nbsp;concatenate&amp;nbsp;of&amp;nbsp;customers&amp;nbsp;that&amp;nbsp;belongs&amp;nbsp;to&amp;nbsp;the&amp;nbsp;ID's&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;2-&lt;CODE class=" language-sas"&gt;CAT_distinct_Customers&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;It is same as&amp;nbsp;&lt;CODE class=" language-sas"&gt;CAT_Customers&amp;nbsp; but&amp;nbsp;after&amp;nbsp;clean&amp;nbsp;duplicate&amp;nbsp;values&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have1;
Input ID Customer1 Customer2 Customer3 CAT_Customers $;
cards;
111111 11 33 22 11,22,33
222222 11 . . 11
444444 22 . . 22
666666 33 . . 33
555555 44 . . 44
;
Run;

Data Have2;
input Customer ID1 ID2  CAT_ID  $20.;
cards;
11 111111 222222 111111,222222
33 111111 666666 111111,666666
22 111111 444444 111111,444444
11 111111 222222 111111,222222
44 555555 .  555555
;
Run;

Data want1;
Input Customer ID1 ID2  CAT_ID $14. CAT_Customers $12. CAT_distinct_Customers $;
cards;
11 111111 222222 111111,222222 11,22,33,11 11,22,33
33 111111 666666 111111,666666 11,22,33,33 11,22,33
22 111111 444444 111111,444444 11,22,33,22 11,22,33
11 111111 222222 111111,222222 11,22,33,11 11,22,33
44 555555 .  555555 44
;
Run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Feb 2022 10:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797451#M287544</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-02-20T10:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate of customer accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797484#M313516</link>
      <description>&lt;P&gt;Are you actually interested in CAT_Customers? Or just the distinct list?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Feb 2022 18:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797484#M313516</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-02-20T18:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate of customer accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797487#M313519</link>
      <description>I need concatenate distinct list of all customers that belong to the ID'S of each customer</description>
      <pubDate>Sun, 20 Feb 2022 18:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797487#M313519</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-02-20T18:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate of customer accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797497#M313528</link>
      <description>The task is to create CAT_distinct_Customers</description>
      <pubDate>Sun, 20 Feb 2022 20:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797497#M313528</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-02-20T20:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate of customer accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797545#M313556</link>
      <description>&lt;P&gt;What have you tried?&lt;/P&gt;
&lt;P&gt;Have you create CAT_Customers and CAT_ID? Are they necessary?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Feb 2022 06:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797545#M313556</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-02-21T06:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate of customer accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797556#M313560</link>
      <description>&lt;P&gt;Before creating the "Want", i fixed some issues with your "have" datasets: IDs should always be alphanumeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.Have1;
   length ID $ 5 Customer1-Customer3 $ 2 Cat_Customers $ 20;
   infile cards missover delimiter='|';
   input Id Customer1 Customer2 Customer3 Cat_Customers;
   cards;
111111|11|33|22|11,22,33
222222|11| | |11
444444|22| | |22
666666|33| | |33
555555|44| | |44
;
run;

data work.Have2;
   length Customer $ 2 Id_1-Id_2 $ 5 Cat_Ids $ 50;
   infile cards missover delimiter='|';
   input Customer Id_1 Id_2 Cat_Ids;
   cards;
11|111111|222222|11111,22222
33|111111|666666|11111,66666
22|111111|444444|11111,44444
11|111111|222222|11111,22222
44|555555| |55555
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One could, of course, bring the data you have in &lt;EM&gt;better&lt;/EM&gt; form, but this hardly helps to get the job done.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set Have2;
   
   if _n_ = 1 then do;
      if 0 then set work.Have1(keep= Id Cat_Customers);
      declare hash h(dataset: 'work.Have1(keep= Id Cat_Customers)');
      h.defineKey('Id');
      h.defineData('Cat_Customers');
      h.defineDone();
   end;
   
   length Customer_List CAT_distinct_Customers $ 100;
   array list Id_:;
   
   do i = 1 to dim(list);
      if not missing(list[i]) then do;
         rc = h.find(key: list[i]);
         
         Customer_List = catx(',', Customer_List, Cat_Customers);
         
         if missing(CAT_distinct_Customers) then do;
            CAT_distinct_Customers = Cat_Customers;
         end;
         else do;
            do j = 1 to countw(Cat_Customers, ',');
               cust = scan(Cat_Customers, j, ',');
               
               if not findw(CAT_distinct_Customers, cust, ',', 't') then do;
                  CAT_distinct_Customers = catx(',', CAT_distinct_Customers, cust);
               end;
            end;
         end;
      end;
   end;
   
   drop Id Cat_Customers i j cust rc;
   rename Customer_List = Cat_Customers;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Feb 2022 08:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797556#M313560</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-02-21T08:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate of customer accounts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797585#M313569</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have1;
Input ID Customer1 Customer2 Customer3 CAT_Customers $;
cards;
111111 11 33 22 11,22,33
222222 11 . . 11
444444 22 . . 22
666666 33 . . 33
555555 44 . . 44
;
Run;

Data Have2;
input Customer ID1 ID2  CAT_ID  $20.;
cards;
11 111111 222222 111111,222222
33 111111 666666 111111,666666
22 111111 444444 111111,444444
11 111111 222222 111111,222222
44 555555 .  555555
;
Run;


option missing=' ';
data want;
 if _n_=1 then do;
   if 0 then set have1(keep=id CAT_Customers);
   declare hash h(dataset:'have1');
   h.definekey('ID');
   h.definedata('CAT_Customers');
   h.definedone();
 end;
set have2;
length  new_CAT_Customers CAT_distinct_Customers  $ 200;

call missing(CAT_Customers);
rc=h.find(key:ID1);
CAT_distinct_Customers=catx(',',CAT_distinct_Customers,CAT_Customers);

call missing(CAT_Customers);
rc=h.find(key:ID2);
CAT_distinct_Customers=catx(',',CAT_distinct_Customers,CAT_Customers);

do i=1 to countw(CAT_distinct_Customers,', ');
temp=scan(CAT_distinct_Customers,i,',');  
if not findw(new_CAT_Customers,strip(temp),', ') then new_CAT_Customers=catx(',',new_CAT_Customers,temp) ;
end;
drop id CAT_Customers rc i temp;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Feb 2022 12:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-of-customer-accounts/m-p/797585#M313569</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-02-21T12:13:17Z</dc:date>
    </item>
  </channel>
</rss>

