<?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: phone number compare in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645506#M192991</link>
    <description>&lt;P&gt;Is it too much to ask that you check the code you post?&lt;/P&gt;
&lt;P&gt;Your code does not load the data properly..&lt;/P&gt;
&lt;P&gt;Both inputs statements are erroneous. They should read this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input ph1 :$10. type1 :$1. ph2 :$10. @25 type2 :$1. ph3 :$10.  type3 :$1. ph4 :$10. type4 :$1. @53 ID :$5.;
input ph $10.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set PHN;
  array INPHN [4] PH1-PH4;
  array INTYP [4] TYPE1-TYPE4;
  array OUTPHN [4] $10;
  array OUTTYP [4] $1;
  if _N_=1 then do;
    dcl hash H(dataset:'LOOKUP');
    H.definekey('PH');
    H.definedone(); 
    if 0 then set LOOKUP;
  end;
  do _I=1 to 4;
    PH=INPHN[_I];   
    if H.find()=0 then do;     
      _FOUND=sum(_FOUND,1); 
      OUTPHN[_FOUND]=INPHN[_I];
      OUTTYP[_FOUND]=INTYP[_I]; 
    end;
  end;
  drop PH: TYP: _:;
  rename OUTPHN1-OUTPHN4 = PHN1-PHN4
         OUTTYP1-OUTTYP4 = TYP1-TYP4 ;
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;</description>
    <pubDate>Wed, 06 May 2020 21:53:06 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-05-06T21:53:06Z</dc:date>
    <item>
      <title>phone number compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645477#M192970</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need help with matching phone numbers from two different data sources. Basically I have a "phn" dataset with list of phone numbers and phone type for each ID and I want to do a compare/vlookup with another table that has valid phone numbers.&amp;nbsp; If&amp;nbsp; a phone number from phn dataset matches with phone number in&amp;nbsp; lookup table then I want to capture that matching phone number along with type for that ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is my date:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data phn;&lt;BR /&gt;input ph1 $10. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/70859"&gt;@12&lt;/a&gt; type1 $1. ph2 $10. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/54795"&gt;@25&lt;/a&gt; type2 $1. ph3 $10. @38 type3 $1. ph4 $10. @51 type4 $1. @53 ID $5.;&lt;BR /&gt;infile cards;&lt;BR /&gt;cards;&lt;BR /&gt;5872584458 B 2478569877 B 8796532587 C 3698712587 C 78987&lt;BR /&gt;9245879578 C 2357895554 B 6048795248 C 2478965479 B 65989&lt;BR /&gt;4578956567 B 2358984155 C 2879241533 B 6987858766 C 24789&lt;BR /&gt;4897568698 C 2258734789 C 3697489567 B 8972314668 C 23272&lt;BR /&gt;3974138688 B 3198766989 B 8658656767 C 8658656767 B 32897&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Data lookup;&lt;BR /&gt;input ph;&lt;BR /&gt;infile cards;&lt;BR /&gt;cards;&lt;BR /&gt;2478569877 &lt;BR /&gt;6048795248&lt;BR /&gt;2357895554&lt;BR /&gt;2723450563&lt;BR /&gt;8658656767&lt;BR /&gt;3697489567&lt;BR /&gt;1245784564&lt;BR /&gt;2368756875&lt;/P&gt;
&lt;P&gt;3198766989&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My desired output is:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ID ph1 type1 ph2 type2 ph2 type2&lt;BR /&gt;78987 2478569877 B&lt;BR /&gt;65989 6048795248 C 2357895554 B&lt;BR /&gt;24789&lt;BR /&gt;23272 3697489567 B&lt;BR /&gt;32897 8658656767 B 8658656767 C 3198766989 B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that for ID 32897 I have listed the same phone number twice in my output. The difference is type, one phone number type B and the other has type C.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your time and help!!&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 23:45:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645477#M192970</guid>
      <dc:creator>vicky07</dc:creator>
      <dc:date>2020-05-05T23:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: phone number compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645506#M192991</link>
      <description>&lt;P&gt;Is it too much to ask that you check the code you post?&lt;/P&gt;
&lt;P&gt;Your code does not load the data properly..&lt;/P&gt;
&lt;P&gt;Both inputs statements are erroneous. They should read this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input ph1 :$10. type1 :$1. ph2 :$10. @25 type2 :$1. ph3 :$10.  type3 :$1. ph4 :$10. type4 :$1. @53 ID :$5.;
input ph $10.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set PHN;
  array INPHN [4] PH1-PH4;
  array INTYP [4] TYPE1-TYPE4;
  array OUTPHN [4] $10;
  array OUTTYP [4] $1;
  if _N_=1 then do;
    dcl hash H(dataset:'LOOKUP');
    H.definekey('PH');
    H.definedone(); 
    if 0 then set LOOKUP;
  end;
  do _I=1 to 4;
    PH=INPHN[_I];   
    if H.find()=0 then do;     
      _FOUND=sum(_FOUND,1); 
      OUTPHN[_FOUND]=INPHN[_I];
      OUTTYP[_FOUND]=INTYP[_I]; 
    end;
  end;
  drop PH: TYP: _:;
  rename OUTPHN1-OUTPHN4 = PHN1-PHN4
         OUTTYP1-OUTTYP4 = TYP1-TYP4 ;
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;</description>
      <pubDate>Wed, 06 May 2020 21:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645506#M192991</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-06T21:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: phone number compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645521#M192996</link>
      <description>&lt;P&gt;Transpose your dataset to long format, and any further coding will be a piece of cake:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data phn;
input
  ph1 :$10.
  type1 :$1.
  ph2 :$10.
  type2 :$1.
  ph3 :$10.
  type3 :$1.
  ph4 :$10.
  type4 :$1.
  ID $5.
;
cards;
5872584458 B 2478569877 B 8796532587 C 3698712587 C 78987
9245879578 C 2357895554 B 6048795248 C 2478965479 B 65989
4578956567 B 2358984155 C 2879241533 B 6987858766 C 24789
4897568698 C 2258734789 C 3697489567 B 8972314668 C 23272
3974138688 B 3198766989 B 8658656767 C 8658656767 B 32897
;

proc sort data=phn;
by id;
run;

proc transpose data=phn out=trans;
by id;
var ph: type:;
run;

data trans2;
set trans;
seq = input(compress(_name_,'','kd'),best.);
_name_ = compress(_name_,'','d');
run;

proc sort data=trans2;
by id seq;
run;

proc transpose data=trans2 out=have (drop=_name_);
by id seq;
id _name_;
var col1;
run;

data lookup;
input ph :$10.;
infile cards;
cards;
2478569877 
6048795248
2357895554
2723450563
8658656767
3697489567
1245784564
2368756875
3198766989
;

data want;
set have;
if _n_ = 1
then do;
  declare hash l (dataset:"lookup");
  l.definekey("ph");
  l.definedone();
end;
if l.check() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 May 2020 06:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645521#M192996</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-06T06:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: phone number compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645640#M193024</link>
      <description>Sorry about the typo in the input statement.  Thank you very much for the solution!!</description>
      <pubDate>Wed, 06 May 2020 15:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645640#M193024</guid>
      <dc:creator>vicky07</dc:creator>
      <dc:date>2020-05-06T15:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: phone number compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645745#M193059</link>
      <description>Thank you very much!</description>
      <pubDate>Wed, 06 May 2020 22:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/phone-number-compare/m-p/645745#M193059</guid>
      <dc:creator>vicky07</dc:creator>
      <dc:date>2020-05-06T22:26:12Z</dc:date>
    </item>
  </channel>
</rss>

