<?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: FInding value present before appending in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601214#M173859</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=month_tab_oct2019;
by key account_num  reporting_date year;
run;

proc sort
  data=hist_mart (keep=key account_num  reporting_date year)
  out=lookup
;
by key account_num  reporting_date year;
run;

data month_append;
merge
  month_tab_oct2019 (in=in_app)
  lookup (in=in_look)
;
by key account_num  reporting_date year;
if in_app and not in_look;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 03 Nov 2019 09:24:36 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-11-03T09:24:36Z</dc:date>
    <item>
      <title>FInding value present before appending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601209#M173857</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a monthly table containing 4000000 observations and Historical table containing around 16700000 observations (Oracle table) On monthly loading day, I use proc append to append data to historical table. However, after 1-2 hours loading, it usually fails giving unique key violation error. Hence, I need to write validation code before proc append. There is unique key on target table for 4 variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dummy Source data looks like as below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Key&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Account Num&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Premium&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Balance&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Outstanding&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Source_ID&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Reporing Date&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Year&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;6665&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;677&lt;/TD&gt;&lt;TD&gt;444&lt;/TD&gt;&lt;TD&gt;Customer Care&lt;/TD&gt;&lt;TD&gt;12-Oct-19&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;34&lt;/TD&gt;&lt;TD&gt;445&lt;/TD&gt;&lt;TD&gt;899&lt;/TD&gt;&lt;TD&gt;556&lt;/TD&gt;&lt;TD&gt;888&lt;/TD&gt;&lt;TD&gt;Bank&lt;/TD&gt;&lt;TD&gt;17-Oct-19&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;554&lt;/TD&gt;&lt;TD&gt;900&lt;/TD&gt;&lt;TD&gt;777&lt;/TD&gt;&lt;TD&gt;998&lt;/TD&gt;&lt;TD&gt;Partner Site&lt;/TD&gt;&lt;TD&gt;04-Oct-19&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7479&lt;/TD&gt;&lt;TD&gt;4782&lt;/TD&gt;&lt;TD&gt;9087&lt;/TD&gt;&lt;TD&gt;655&lt;/TD&gt;&lt;TD&gt;978&lt;/TD&gt;&lt;TD&gt;Bank&lt;/TD&gt;&lt;TD&gt;16-Oct-19&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7657&lt;/TD&gt;&lt;TD&gt;5468&lt;/TD&gt;&lt;TD&gt;886&lt;/TD&gt;&lt;TD&gt;5467&lt;/TD&gt;&lt;TD&gt;665&lt;/TD&gt;&lt;TD&gt;Bank&lt;/TD&gt;&lt;TD&gt;16-Oct-19&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And below is my Target Historical Table before&amp;nbsp; loading&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Key&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Account Num&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Premium&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Balance&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Outstanding&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Source_ID&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Reporing Date&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Year&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;45489&lt;/TD&gt;&lt;TD&gt;777&lt;/TD&gt;&lt;TD&gt;887&lt;/TD&gt;&lt;TD&gt;899&lt;/TD&gt;&lt;TD&gt;Customer Care&lt;/TD&gt;&lt;TD&gt;12-Oct-18&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;34&lt;/TD&gt;&lt;TD&gt;445&lt;/TD&gt;&lt;TD&gt;899&lt;/TD&gt;&lt;TD&gt;556&lt;/TD&gt;&lt;TD&gt;888&lt;/TD&gt;&lt;TD&gt;Bank&lt;/TD&gt;&lt;TD&gt;17-Oct-18&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;554&lt;/TD&gt;&lt;TD&gt;900&lt;/TD&gt;&lt;TD&gt;777&lt;/TD&gt;&lt;TD&gt;998&lt;/TD&gt;&lt;TD&gt;Partner Site&lt;/TD&gt;&lt;TD&gt;04-Oct-18&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;554&lt;/TD&gt;&lt;TD&gt;900&lt;/TD&gt;&lt;TD&gt;777&lt;/TD&gt;&lt;TD&gt;998&lt;/TD&gt;&lt;TD&gt;Partner Site&lt;/TD&gt;&lt;TD&gt;04-Oct-19&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unique Key constraints is on Key, Account Num, Reporting Date and Year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc append base=Hist_mart data=month_tab_oct2019 force; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this fails for account no 554 (Record no 3 in source) which is correct.&amp;nbsp; My problem is how do I findout before applying proc append.&amp;nbsp; Any help or ideas is really appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 07:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601209#M173857</guid>
      <dc:creator>Swapnil_21</dc:creator>
      <dc:date>2019-11-03T07:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: FInding value present before appending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601214#M173859</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=month_tab_oct2019;
by key account_num  reporting_date year;
run;

proc sort
  data=hist_mart (keep=key account_num  reporting_date year)
  out=lookup
;
by key account_num  reporting_date year;
run;

data month_append;
merge
  month_tab_oct2019 (in=in_app)
  lookup (in=in_look)
;
by key account_num  reporting_date year;
if in_app and not in_look;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Nov 2019 09:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601214#M173859</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-03T09:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: FInding value present before appending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601228#M173862</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Assuming that monthly data are &lt;STRONG&gt;all&lt;/STRONG&gt; OCT2019 and the fact that historic data is huge&lt;/P&gt;
&lt;P&gt;I suggest to add a WHERE statement to the 2nd sort step, in order to eliminate time execution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=hist_mart (keep=key account_num  reporting_date year
        where=(reporting_date between '01oct2019'd and '31oct2019'd))
  out=lookup
;
by key account_num  reporting_date year;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Nov 2019 14:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601228#M173862</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-11-03T14:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: FInding value present before appending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601238#M173867</link>
      <description>&lt;P&gt;Good idea. Thinking about it, I'd draw the min/max date first from the update dataset, just to be sure:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql no print;
select min(reporting_date), max(reporting_date) into :mindate, maxdate
from month_tab_oct2019;
quit;

proc sort
  data=hist_mart (
    keep=key account_num  reporting_date year
    where=(reporting_date between &amp;amp;mindate. and &amp;amp;maxdate.))
  )
  out=lookup
;
by key account_num reporting_date year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You never know what people put into datasets &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 15:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601238#M173867</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-03T15:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: FInding value present before appending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601262#M173877</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292735"&gt;@Swapnil_21&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What should happen if there is a matching key? Update, just ignore or raise an error? Do you want to insert whatever is possible or not insert anything if there is a matching key.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using Oracle:&lt;/P&gt;
&lt;P&gt;I would first upload your SAS data into an Oracle staging table and have all the remaining processing done in Oracle using explicit pass-through SQL. Depending on the details of the load logic you need using an Oracle SQL Merge statement could eventually make it very simple to deal with your data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2+ hours for Inserting 400K records sounds like bad performance. Changing some of the SAS parameters like insertbuff and dbcommit might help to improve performance. Also bulk-loading could eventually speed-up time especially if loading into a staging table.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 22:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601262#M173877</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-03T22:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: FInding value present before appending</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601338#M173925</link>
      <description>&lt;P&gt;Instead of using append, you could use a data step to add the values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data oralib.target;
  modify oralib.target monthly_source;
  by Key Account_Num Reporting_Date Year;
  if _iorc_=%sysrc(_DSENMR) then do; /* key not found in master data */
    _error_=0;
    output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As the Oracle database is checking the key values anyway (because of the unique key restraint), this may be just as fast as PROC APPEND.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 10:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FInding-value-present-before-appending/m-p/601338#M173925</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-11-04T10:41:11Z</dc:date>
    </item>
  </channel>
</rss>

