<?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/304656#M64859</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37160"&gt;@KiranMaddi﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You've started a really interesting discussion here and&amp;nbsp;I'm spending unreasonable time with it because&amp;nbsp;I'm actually also learning something.&lt;/P&gt;
&lt;P&gt;I believe you're now at the point of "it depends".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't want to go for an "in-place" approach using MODIFY then the one thing you want to concentrate on is to keep I/O to a minimum. This means you want to minimize read/write operations and make best use of your actual environment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are also a few data set option which you can set when creating a ds which can improve I/O.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n0a1u9b2buxl5yn1nv12rnoppiip.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n0a1u9b2buxl5yn1nv12rnoppiip.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How far you need&amp;nbsp;to take things will depend on how big your current performance problem actually is (are some quick-wins sufficient or do you need to squeeze out the last drop?).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both the UPDATE and MERGE statement fully recreate the master ds and as you have Updates and Inserts I would go for Merge.&lt;/P&gt;
&lt;P&gt;If both the Master and Transaction ds are indexed then the BY statement could use the index and the ds wouldn't need to be physically sorted that way. That's what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;was talking about using UPDATE with an index.&lt;/P&gt;
&lt;P&gt;I've done some testing with your volumes and the results don't support such an approach (the merge took around 6 minutes on my machine). So for merging have your data sets physically sorted in the way you refer to them in the By statement when merging (that took me&amp;nbsp;40 seconds in my environment which is more or less the time required to write the master ds).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now: If you've got control how the master DS is sorted then just have it sorted ONCE (once off job). A Merge with by group processing maintains the sort order and&amp;nbsp;you don't need to run a sort every single time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On my laptop using the V9 engine with compression turned performance was&amp;nbsp;as good or even better than most other approaches (the merge&amp;nbsp;took around 40 seconds for a compressed DS, only the MODIFY with an index and uncompressed data was significantly faster with 20 seconds).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On my laptop the main time spent is for "write to disc" - initial creation of the master ds took already around 40 seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now these timings could be very different in your environment and your records and you will have to run some tests to come up with the right strategy (if required, the quick win will be to no more sort your master DS every single time).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that your master DS is quite huge even when compressed, I still would go for the SPDE engine to keep file size in a reasonable area. Using the SPDE engine could also be beneficial for data retrieval (eg. multithreading with indexes and where clauses) and I'm sure that also your OPS team prefers to have reasonable file sizes for backup and recovery processes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're happy to have your master ds sorted the way you need it for a Merge with By group processing then using&amp;nbsp;the hash approach as proposed by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;won't be faster as it still requires a read/write operation. Only consider the hash approach if your master ds is sorted differently AND you can be sure that you can fit the full transaction dataset always into memory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below a code version using MERGE which assumes that the Master DS is already sorted as expected by the By statement. This is basically your initial code without the sort. The merge took around 40 seconds in my environment.&lt;/P&gt;
&lt;P&gt;I'm expecting your real data to have a much wider PDV and writing the full data could take up much more time. So here using the SPDE engine and/or a MODIFY statement or at least using the "fastest disk available" could make a big difference in end-to-end run-times.&lt;/P&gt;
&lt;P&gt;The ds option "sortedby=date id" is not necessary for the merge BUT it can be beneficial to to have this attribute set on a ds for data retrieval as it can allow the&amp;nbsp;compiler to eventually take a better execution path (especially for SQL queries, or where clauses with the SPDE engine).&lt;/P&gt;
&lt;P&gt;There had been the suggestion to use the "PRESORTED" option with Proc Sort so that sorting only happens when it is required. For Proc Sort to determine if sorting is required it still would need to scan (read) the source ds. I'm not sure but eventually with attribute&amp;nbsp;&lt;SPAN&gt;"sortedby=date id" set, Proc Sort wouldn't scan the ds anymore. If that's true then you could have in your code a Proc Sort for the Master ds - just make sure that you use option "PRESORTED" and set attibute "sortedby" on the output ds (out= in proc sort; with same ds name than in data=).&lt;/SPAN&gt;&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 */
/* partsize of 4GB is for uncompressed. */
/* Try to end up with around 4 partitions per "Data folder" and choose Partsize accordingly */
/*libname spdetest spde ("%sysfunc(pathname(work))")*/
/*    datapath=("%sysfunc(pathname(work))\data" "D:\temp\SPDE\data")*/
/*    indexpath=("%sysfunc(pathname(work))\index")*/
/*    partsize=4G*/
/*  ;*/

libname spdetest (work);

/* create master data set */
/*data spdetest.master(compress=yes);*/
data spdetest.master(compress=yes sortedby=date id);
  length other_var $10 big_var $1000;
  retain other_var 'MASTER' big_var 'big';
  do date= '01jul2016'd to '31jul2016'd, '01aug2016'd, '01sep2016'd;
      do id=1,2,3,5, 100 to 10**6;
      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;

proc sort data=trans;
  by date id;
run;

/* merge master with trans */
data spdetest.master(compress=yes sortedby=date id);
  merge spdetest.master trans ;
  by date id;
run;

data retrieval;
  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;</description>
    <pubDate>Fri, 14 Oct 2016 14:05:40 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2016-10-14T14:05:40Z</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>

