<?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: Table look up using merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Table-look-up-using-merge/m-p/579744#M164616</link>
    <description>&lt;P&gt;Than you for the quick response. I accepted your solution.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Aug 2019 20:01:05 GMT</pubDate>
    <dc:creator>mauri0623</dc:creator>
    <dc:date>2019-08-07T20:01:05Z</dc:date>
    <item>
      <title>Table look up using merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Table-look-up-using-merge/m-p/579734#M164611</link>
      <description>&lt;P&gt;DAI and PIPS are two SAS datasets. PIPS could have missing values for the variables ALC, ODN, LOA, and TAS. We want to lookup the DAI dataset and populate the missing variables from PIPS. We have 8 different Scenarios as stated on the attached document. I have created the below code that takes care of the scenario 1 and 5. However I am stocked on other scenarios. We don't have to use hash merging necessarily. Anything that can cover the scenarios is fine with me. Your help is highly and professionally appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards, Mauri Esfandiari&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code for scenarios 1 and 5 is below,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/****************************************************&lt;/P&gt;&lt;P&gt;Use the SAS has merge to find the matches between&lt;/P&gt;&lt;P&gt;the two tables and if they match place them in the&lt;/P&gt;&lt;P&gt;PIPS_DAI_Match table and if they don't then place&lt;/P&gt;&lt;P&gt;them in the table Error_File.&lt;/P&gt;&lt;P&gt;****************************************************/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; sas_perm.PIPS_DAI_Match sas_perm.Error_File(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=rc);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.pips_no_sudo;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _N_ = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;declare&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; hash h(dataset:&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'work.dai_fixed'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;h.defineKey(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'ipac'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;h.defineData(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'OBLIGATING_DOC_NO'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'accounting'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'tas'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;h.defineDone();&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; missing(OBLIGATING_DOC_NO, accounting, tas);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.dai_fixed;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rc=h.find();&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; rc &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; sas_perm.PIPS_DAI_Match;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; sas_perm.Error_file;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2019 19:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Table-look-up-using-merge/m-p/579734#M164611</guid>
      <dc:creator>mauri0623</dc:creator>
      <dc:date>2019-08-07T19:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Table look up using merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Table-look-up-using-merge/m-p/579735#M164612</link>
      <description>&lt;P&gt;You can do all scenarios in the same data step. I assumed that variables are numeric (missing = .).&lt;/P&gt;
&lt;P&gt;Scenario 6 is not clear - where are the other variables ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_ok want_err;
 merge pips(in=inp)
       dai (in=ind rename=(alc=Dalc odn=Dodn loa=Dloa tas=Dtas);
  by &amp;lt;identifier&amp;gt;;
      if inp;
      if Dalc=. and Dodn=. and Dloa=. and Dtas=. 
         then output want_err; 
      else do;
        if odn=. then odn=Dodn;
        if loa=. then loa=Dloa;
        if tas=. then tas-Dtas;
        output want_ok;
     end;&lt;BR /&gt;     drop Dalc Dodn Dloa Dtas;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Aug 2019 19:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Table-look-up-using-merge/m-p/579735#M164612</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-08-07T19:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Table look up using merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Table-look-up-using-merge/m-p/579744#M164616</link>
      <description>&lt;P&gt;Than you for the quick response. I accepted your solution.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2019 20:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Table-look-up-using-merge/m-p/579744#M164616</guid>
      <dc:creator>mauri0623</dc:creator>
      <dc:date>2019-08-07T20:01:05Z</dc:date>
    </item>
  </channel>
</rss>

