<?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: Find client number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-client-number/m-p/982917#M379415</link>
    <description>&lt;P&gt;Most likely i overlook a detail of the specs. I am not sure what "As I said the client number should be matching to all Id numbers under the application (This is the criteria)" means exactly: why is "033948333" mapped to 1 and not to 3?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If always the first appearance in tbl2 defined the correct mapping from&amp;nbsp;ID_number to client_number, a feature of hash objects can be used to simplify the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;
    set work.tbl1;

    if _n_ = 1 then do;
        if 0 then set work.tbl2; /* adds variables to the pdv */

        declare hash h(dataset: "work.tbl2", ordered: "yes");
        h.defineKey("ID_number");
        h.defineData("client_number");
        h.defineDone();
    end;

    if h.find() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Feb 2026 11:57:41 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2026-02-03T11:57:41Z</dc:date>
    <item>
      <title>Find client number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-client-number/m-p/982777#M379395</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have two data sets.&lt;/P&gt;
&lt;P&gt;In first one have fields application number and id number.&lt;/P&gt;
&lt;P&gt;In second have fields ID number and client number.&lt;/P&gt;
&lt;P&gt;A person (Or two people-husband and wife) arrive to company office and ask details about open a client account.&lt;/P&gt;
&lt;P&gt;The information is in first table (application_number ID_number).&lt;/P&gt;
&lt;P&gt;Here-&lt;/P&gt;
&lt;P&gt;Id numbers-033948333+041876222&amp;nbsp; &amp;nbsp; opened application&amp;nbsp;123&lt;/P&gt;
&lt;P&gt;Id number&amp;nbsp;051222222 opened application&amp;nbsp;&amp;nbsp;456&lt;/P&gt;
&lt;P&gt;Id number 718888888 opened application&amp;nbsp; 789&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In second table have information of&amp;nbsp; all existing clients in the company&amp;nbsp; and owners of each client (Id numbers belong to the client)&lt;/P&gt;
&lt;P&gt;Id number&amp;nbsp;033948333&amp;nbsp; belong to multiple clients:1,3&lt;/P&gt;
&lt;P&gt;Id number&amp;nbsp;041876222&amp;nbsp; belong to multiple clients: 1,4&lt;/P&gt;
&lt;P&gt;Id number&amp;nbsp;051222222 belong to one client:5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My task-&lt;/P&gt;
&lt;P&gt;I want to add client number to first table using the information in second table.&lt;/P&gt;
&lt;P&gt;I want to have criteria that all ID numbers under the application must belong to same client number.&lt;/P&gt;
&lt;P&gt;So-&lt;/P&gt;
&lt;P&gt;Id number&amp;nbsp;033948333 and I number&amp;nbsp;041876222 belong both to client 1&lt;/P&gt;
&lt;P&gt;Id number belong to client 5&lt;/P&gt;
&lt;P&gt;Id number&amp;nbsp;718888888 doesn't belong to any client (Client was not opened for him)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to create desired data set using logic?&lt;/P&gt;
&lt;P&gt;As I said the client number should be matching to all Id numbers under the application (This is the criteria)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
input application_number ID_number;
cards;
123 033948333
123 041876222
456 051222222
789 718888888
;
Run;


Data tbl2;
input ID_number client_number;
cards;
033948333 1
033948333 3
041876222 1
041876222 4
051222222 5
;
Run;



Data want;
input application_number ID_number client_number;
cards;
123 033948333 1
123 041876222 1
456 051222222 5
;
Run;

&lt;/CODE&gt;&lt;/PRE&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;When a new person arrive to the company then open a new application and see it in first table.&lt;/P&gt;
&lt;P&gt;When the client open then see it on second table. I want to add client number to first table using the information in second table. The problem is that a specific ID number can open multiple clients number.i want to have criteria that all ID numbers under the application must belong to same client number. I will show you the wanted Data set and my question is how to create this wanted table using logic code&lt;/P&gt;</description>
      <pubDate>Sat, 31 Jan 2026 06:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-client-number/m-p/982777#M379395</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2026-01-31T06:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Find client number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-client-number/m-p/982778#M379396</link>
      <description>&lt;P&gt;I found solution, maybe have other solutions?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
input application_number ID_number;
cards;
123 033948333
123 041876222
456 051222222
789 718888888
;
Run;


Data tbl2;
input ID_number client_number;
cards;
033948333 1
033948333 3
041876222 1
041876222 4
051222222 5
;
Run;



/*Data want;*/
/*input application_numberID_number client_number;*/
/*cards;*/
/*123 033948333 1*/
/*123 041876222 1*/
/*456 051222222 5*/
/*;*/
/*Run;*/


/*Each Id number can beling to multiple cient numbers (tbl2)*/
/*Each application number can have multiple ID numbers (tbl1)*/
/*I want to assign one client number per application */
/*Please note that for simple- There is only one client that is fitting by this criteria*/


proc sql;
create table Help1 as
select application_number,
       count(distinct ID_number) as nr_ID_number_In_Bakasha
from tbl1
group by application_number
;
quit;


proc sql;
create table potential_lak_candidates as
select a.*,b.client_number
from tbl1 as a
inner join tbl2 as b
on a.ID_number=b.ID_number
;
quit;


proc sql;
create table Help2 as
select application_number,client_number,
              count(distinct ID_number) as n_ID_numbers_matched
from potential_lak_candidates
group by application_number,client_number
;
quit;


proc sql;
  create table Help3 as
  select a.application_number,a.client_number
  from Help2 as a
  inner join Help1 as b
   on a.application_number= b.application_number
  where a.n_ID_numbers_matched = b.nr_ID_number_In_Bakasha;
quit;


proc sql;
create table want as
select a.*,b.client_number
from tbl1 as a
left join Help3  as b
on a.application_number=b.application_number
;
quit;

  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Jan 2026 06:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-client-number/m-p/982778#M379396</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2026-01-31T06:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find client number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-client-number/m-p/982782#M379397</link>
      <description>&lt;P&gt;You want this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
input application_number ID_number;
cards;
123 033948333
123 041876222
456 051222222
789 718888888
;
Run;


Data tbl2;
input ID_number client_number;
cards;
033948333 1
033948333 3
041876222 1
041876222 4
051222222 5
;
Run;

proc sql;
create table want as
select a.*,client_number
  from tbl1 as a inner join tbl2 as b 
   on a.ID_number=b.ID_number
    group by application_number,client_number
	 having count(distinct ID_number)=
(select count(distinct ID_number) from tbl1 where application_number=a.application_number);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Jan 2026 08:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-client-number/m-p/982782#M379397</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-01-31T08:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find client number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-client-number/m-p/982917#M379415</link>
      <description>&lt;P&gt;Most likely i overlook a detail of the specs. I am not sure what "As I said the client number should be matching to all Id numbers under the application (This is the criteria)" means exactly: why is "033948333" mapped to 1 and not to 3?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If always the first appearance in tbl2 defined the correct mapping from&amp;nbsp;ID_number to client_number, a feature of hash objects can be used to simplify the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;
    set work.tbl1;

    if _n_ = 1 then do;
        if 0 then set work.tbl2; /* adds variables to the pdv */

        declare hash h(dataset: "work.tbl2", ordered: "yes");
        h.defineKey("ID_number");
        h.defineData("client_number");
        h.defineDone();
    end;

    if h.find() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Feb 2026 11:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-client-number/m-p/982917#M379415</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2026-02-03T11:57:41Z</dc:date>
    </item>
  </channel>
</rss>

