<?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: Alternative to SAS Merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304381#M64795</link>
    <description>&lt;P&gt;You have a master ds with 50 million records and a transaction ds with 60 thousand records but you then fully re-write all the 50 million records every single time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd &amp;nbsp;opt for an approach where you update "in-place" which means you need either to use SQL Insert and Update or a data step Modify statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending how wide your records are I/O will be another consideration. One way to go would be to use the SPDE engine and spread your data over multiple disks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below a fully working code example which uses a data step Modify with an index which doesn't require&amp;nbsp;sorting and reduces I/O as to figure out which records to update only the index file needs to be read.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options fullstimer;

/* create directories in WORK */
data _null_;
  Base_Dir="%sysfunc(pathname(work))";
  rc1=dcreate('data', cats(Base_Dir,'\'));
  rc2=dcreate('index', cats(Base_Dir,'\'));
run;

/* define libname using SPDE engine */
libname spdetest spde ("%sysfunc(pathname(work))")
    datapath=("%sysfunc(pathname(work))\data")
    indexpath=("%sysfunc(pathname(work))\index")
  ;

/* create master data set */
/*data spdetest.master(compress=yes);*/
data spdetest.master;
  length other_var $10 big_var $1000;
  retain other_var 'MASTER' big_var 'big';
  do id=2,3,1,5, 100 to 10**6;
    do date='01sep2016'd, '01aug2016'd, '01jul2016'd to '31jul2016'd;
      output;
    end;
  end;
  format date date9.;
run;

/* create transaction data set */
data trans;
  length other_var $10;
  retain other_var 'TRANS';
  do id=4,2, 50000 to 2000 by -1;
    do date='01sep2016'd, '01oct2016'd;
      output;
    end;
  end;
  format date date9.;
run;

/* create composite index on master data set if it doesn't exist already */
%macro create_index();
  %local exist;
  proc sql noprint;
    select name into :exist
    from dictionary.indexes
    where libname='SPDETEST' and memname='MASTER' and upcase(name)='DTID'
    ;
  quit;

  %if %bquote(&amp;amp;exist) = %bquote() %then
    %do;
      proc datasets lib=spdetest nolist noprint;
        modify master(asyncindex=yes);
          index create dtid=(date id) / unique;
      quit;
    %end;
%mend;
%create_index();


/* update &amp;amp; insert master data set in place with transactions */
data spdetest.master;
  set trans(keep=date id);
  modify spdetest.master key=dtid;
  set trans(drop=date id);

  select (_iorc_);
    /* updates */
    when (%sysrc(_sok))
      do;
        replace;
      end;

    /* inserts */
    when (%sysrc(_dsenom))
      do;
        output;
        _error_=0;
      end;

    otherwise
      do;
        put
          'An unexpected I/O error has occurred.'/
          'Check your data and your program';
        _error_=0;
        stop;
      end;
  end;

run;

data test;
  set spdetest.master;
  where other_var='TRANS';
run;

proc contents data=spdetest.master;
run;quit;&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;I've done testing of above code with and without compression of the master ds. Compression reduced size more than 90% and the ds got much faster created BUT the Update/Insert (modify) step took with compression on my laptop more than 4 minutes real time where the test without compression run&amp;nbsp;within 20 seconds (and that's with 33 million rows in the master and 90 thousand rows in the transaction ds).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're going for the SPDS engine then read the documentation. There are many more options available to tweak performance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When deciding how to spread out the data and whether to use compression or not then consider also data retrieval. I would assume that data retrieval will be considerably faster with compression so eventually this is in the end more important than a daily incremental load running for 15 minutes longer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Oct 2016 00:08:32 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2016-10-14T00:08:32Z</dc:date>
    <item>
      <title>Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304046#M64673</link>
      <description>&lt;P&gt;Hello all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS 9.3&lt;/P&gt;
&lt;P&gt;EG 5.1&lt;/P&gt;
&lt;P&gt;Windows 7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two tables History,Transaction. History table is huge(51million records). We need to update the history table everyday with the transaction table i.e Update already exisiting records and Insert new records. But the problem with the merge is sorting both the tables which is taking almost 3.5 hours and the merge around 3.5 hours.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Usually we do Delete and Insert in SQL. Looking to find a way to make this process a bit quicker on SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking forward for your valuable suggestions.&lt;/P&gt;
&lt;PRE&gt;  
Proc sort Data =History ;
by common_KEY;
run;

Proc sort Data =transaction;
by common_KEY;
run;



DATA History;
MERGE History transaction;       
BY common_KEY;
RUN;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 12:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304046#M64673</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-10-12T12:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304048#M64674</link>
      <description>&lt;P&gt;If your existing HISTORY is the result of the same process there is no need to sort it again. Merge preserves the order in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Usually, when dealing with large tables, one needs to dive into performance tuning:&lt;/P&gt;
&lt;P&gt;- have a separate UTILLOC defined in the sasv9.cfg file. UTILLOC is the place where the utility file during a sort is stored.&lt;/P&gt;
&lt;P&gt;- have both WORK and UTILLOC physically separated on the fastest disks available (SSD preferred, nowadays).&lt;/P&gt;
&lt;P&gt;- try to avoid reading and writing simultaneously on the same physical resource; have source and target tables during the merge on physically separate disks.&lt;/P&gt;
&lt;P&gt;- use the compress=yes option to reduce physical dataset size, if that is not already in place.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 13:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304048#M64674</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-12T13:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304050#M64675</link>
      <description>Hi Kurt&lt;BR /&gt;&lt;BR /&gt;Thanks for your prompt response.&lt;BR /&gt;&lt;BR /&gt;I have already go the compress option enabled. Also if I have to talk about your suggestion to avoid reading and writing simultaneously. We use to do that but I would say there is a risk in that. If at all the merge fails the data step would end up creating an empty table which will be used to update the Master table. i.e overwriting the history table with empty work table. This happened once, since then we are using the same physical table for reading and writing as the dataset will not be replaced in case of any error.</description>
      <pubDate>Wed, 12 Oct 2016 13:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304050#M64675</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-10-12T13:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304053#M64676</link>
      <description>RE: If your existing HISTORY is the result of the same process there is no need to sort it again. Merge preserves the order in the output.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;That's an interesting point. I never knew that Merge would preserve the order. If this is the case I would never need to sort the histoty table?</description>
      <pubDate>Wed, 12 Oct 2016 13:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304053#M64676</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-10-12T13:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304054#M64677</link>
      <description>&lt;P&gt;Until we switch to a really fast SAN environment, we have this setup:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Production data on SAN&lt;/P&gt;
&lt;P&gt;WORK location internally in the server, separate disk(s) for UTILLOC&lt;/P&gt;
&lt;P&gt;Additional disks in the server, used as additional temporary locations&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The process would look like this:&lt;/P&gt;
&lt;P&gt;- sort dataset1 from production to temp1&lt;/P&gt;
&lt;P&gt;- sort dataset2 from production to temp2&lt;/P&gt;
&lt;P&gt;- merge temp1.dataset1 and temp2.dataset2 back to production&lt;/P&gt;
&lt;P&gt;before doing the merge, you can check for &amp;amp;SYSCC=0 to prevent that step in case something went wrong during the sorts or other preliminary steps&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 13:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304054#M64677</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-12T13:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304057#M64678</link>
      <description>&lt;P&gt;Have you tried update/modify instead of merge?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 13:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304057#M64678</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2016-10-12T13:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304058#M64679</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37160"&gt;@KiranMaddi&lt;/a&gt; wrote:&lt;BR /&gt;RE: If your existing HISTORY is the result of the same process there is no need to sort it again. Merge preserves the order in the output.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;That's an interesting point. I never knew that Merge would preserve the order. If this is the case I would never need to sort the histoty table?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Absolutely. The only difference is that the sort bit in the table header is not set, but that does not affect a further merge.&lt;/P&gt;
&lt;P&gt;As long as you never resort the HISTORY table by another column, you can merge without sorting.&lt;/P&gt;
&lt;P&gt;Part of the efficiency of the data step merge is its simplicity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if you do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort dataset1;
by id;
run;

proc sort dataset2;
by id;
run;

data dataset3;
set
  dataset1
  dataset2
;
by id; *!;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the final dataset3 will be sorted by id. This is useful when interleaving datasets with identical columns.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 13:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304058#M64679</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-12T13:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304061#M64680</link>
      <description>Hi error_prone&lt;BR /&gt;&lt;BR /&gt;Yes, I have. It is taking as much time as the merge does as we still need to sort the datasets.</description>
      <pubDate>Wed, 12 Oct 2016 13:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304061#M64680</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-10-12T13:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304080#M64684</link>
      <description>&lt;P&gt;OK. Assuming there are unique ID number for each row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data history;
 do id=1 to 100;
   x='x';output;
 end;
run;

data transaction;
 do id=90 to 102;
  x='y';output;
 end;
run;

data want;
 if _n_=1 then do;
  if 0 then set transaction;
  declare hash h(dataset:'transaction');
  declare hiter hi('h');
  h.definekey('id');
  h.definedata('id','x');
  h.definedone();
 end;
set history end=last;
if h.find()=0 then h.remove();
output;
if last then do;
 do while(hi.next()=0);
  output;
 end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Oct 2016 14:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304080#M64684</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-12T14:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304082#M64685</link>
      <description>&lt;P&gt;You can make an INDEX for this BY variable to avoid PROC SORT again.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 14:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304082#M64685</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-12T14:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304096#M64689</link>
      <description>&lt;P&gt;Thanks a lot Ksharp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The unique index is on 2 variables, so I would expect some duplicates&amp;nbsp;in the ID.&lt;BR /&gt;&lt;BR /&gt; I have never used hashing on SAS. Please,would you mind explaining briefly what the code is doing in the third step?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 14:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304096#M64689</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-10-12T14:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304108#M64692</link>
      <description>Also I noticed in the h.definedata('id','x',), you seem to have specified the varibalenames. What if I have 500 variables for instance?</description>
      <pubDate>Wed, 12 Oct 2016 14:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304108#M64692</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-10-12T14:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304117#M64697</link>
      <description>&lt;P&gt;First of all , you need to know you are doing One-to-One match or Many-to-Many match ?(my code is for one-to-one match)&lt;/P&gt;
&lt;P&gt;Hash Table is a long story, I can't tell you its detail, check documentation on your own.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have lots of variable ,make a macro variable contain all these variables name, Like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select quote(name) into : list separated by ','&lt;/P&gt;
&lt;P&gt;&amp;nbsp;from dictionary.columns&lt;/P&gt;
&lt;P&gt;&amp;nbsp; where .............&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 15:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304117#M64697</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-12T15:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304145#M64709</link>
      <description>Thanks Ksharp.&lt;BR /&gt;&lt;BR /&gt;I will read the documentation.&lt;BR /&gt;&lt;BR /&gt;To answer your question, I do one to many join in which case your code won't work?&lt;BR /&gt;</description>
      <pubDate>Wed, 12 Oct 2016 16:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304145#M64709</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-10-12T16:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304220#M64741</link>
      <description>&lt;P&gt;Yes. My code is only for one-to-one match.&lt;/P&gt;
&lt;P&gt;If you want do one-to-many match. Can you post an example and its output to explain it ?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 02:26:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304220#M64741</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-13T02:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304238#M64751</link>
      <description>&lt;P&gt;KSharp:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like your code, which as you mentioned is meant only for 1 to1 merge.&amp;nbsp; But even so, there are two problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;1. There is no guarantee that the new id's that appended to the end of the old history data set will be in proper order.&amp;nbsp; I think you forgot to include the ORDERED parameter in the hash declaration.&amp;nbsp; That&amp;nbsp; of course is easily fixed, as in&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash h (dataset:'transaction',ordered:'a');&lt;/LI&gt;
&lt;LI&gt;If the old history had a gap in its ID's (say it has ID's 1..49, and 51..100), and the transaction file had an ID that fell into the gap (i.e. id 50 in this example), then that ID would be erroneously placed at the end of the new history file rather than the middle.&amp;nbsp; Not so easily fixed.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 04:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304238#M64751</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-10-13T04:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304239#M64752</link>
      <description>&lt;P&gt;How many records in transaction?&lt;/P&gt;
&lt;P&gt;To complete the very valid answers given so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1- You can use:&lt;/P&gt;
&lt;P&gt;proc sort data=transaction &lt;EM&gt;&lt;STRONG&gt;presorted&lt;/STRONG&gt;&lt;/EM&gt;;&lt;BR /&gt;by common_KEY;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;If the table is already sorted, it is then&amp;nbsp;simply copied. If not, it is sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2- One comment:&lt;/P&gt;
&lt;P&gt;The merge code you show is not necessarily&amp;nbsp;equivalent to a sql delete+insert.&lt;/P&gt;
&lt;P&gt;If you reduce the number of records for one key (transaction has 1 record for the key while history has 2), the merge logic will keep 2 records. Is this what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 04:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304239#M64752</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-10-13T04:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304240#M64753</link>
      <description>&lt;P&gt;KiranMaddi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't neccessarily need to list the variables in the definedata method statement.&amp;nbsp;&amp;nbsp; Given that the hash&amp;nbsp; table is declared with the DATASET:'transaction' option,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash h (dataset:'transaction',ordered:'a')&lt;/P&gt;
&lt;P&gt;then you can use the ALL parameter in the definedata method, as in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedata(all:'Y');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This tells SAS to include all the variables in&amp;nbsp; data set transaction. No need to list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Markk&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 04:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304240#M64753</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-10-13T04:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304276#M64762</link>
      <description>&lt;P&gt;1) Since it is one-to-one match , I think the order doesn't matter.&lt;/P&gt;
&lt;P&gt;2) That is the reason why I suggest OP make an INDEX for that ID variable.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 08:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304276#M64762</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-13T08:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to SAS Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304277#M64763</link>
      <description>Since some keys are new, the hash table solution will not do. The index solution will only be faster than sorting if the transaction table is a lot smaller than the history table.</description>
      <pubDate>Thu, 13 Oct 2016 08:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-SAS-Merge/m-p/304277#M64763</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-10-13T08:26:26Z</dc:date>
    </item>
  </channel>
</rss>

