<?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: Merging two datasets with different but similar columns in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160047#M41728</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Data step is &lt;STRONG&gt;fast&lt;/STRONG&gt; if your dataset is sorted by datetime. You can merge/interleave the 2 datasets.&lt;/P&gt;&lt;P&gt;The problem is, that you cannot use a &lt;STRONG&gt;merge/by&lt;/STRONG&gt; statement, because time stamps are not exactly equal.&lt;/P&gt;&lt;P&gt;You cannot use a &lt;STRONG&gt;set/by&lt;/STRONG&gt; statement, because in that case when we read from one of the datasets, the information from the other dataset is lost.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The solution is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set y(in=inY keep=datetime) x(in=inX keep=datetime);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by datetime;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if inY then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set y;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if inX then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set x;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Jul 2014 09:55:25 GMT</pubDate>
    <dc:creator>gergely_batho</dc:creator>
    <dc:date>2014-07-01T09:55:25Z</dc:date>
    <item>
      <title>Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160040#M41721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I'm currently writing my thesis and I'm facing a serious issue. It would be awesome if you could help me with it.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I want to merge two database. The first one (let's call it TRADES) concerns the trades concerning different stocks, this one goes like that:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" height="174" style="width: 286px; height: 166px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="80"&gt;id_trade&lt;/TD&gt;&lt;TD width="100"&gt;Datetime&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;320&lt;/TD&gt;&lt;TD align="right" class="xl63"&gt;1/02/2014 09:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;240&lt;/TD&gt;&lt;TD align="right" class="xl63"&gt;1/02/2014 09:03&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;356&lt;/TD&gt;&lt;TD align="right" class="xl63"&gt;3/02/2014 09:12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;908&lt;/TD&gt;&lt;TD align="right" class="xl63"&gt;4/02/2014 09:15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;1452&lt;/TD&gt;&lt;TD align="right" class="xl63"&gt;5/02/2014 09:23&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;6543&lt;/TD&gt;&lt;TD align="right" class="xl63"&gt;6/02/2014 09:45&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The second (Let's call it SPREAD) database is like that&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="260"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="100"&gt;Datetime&lt;/TD&gt;&lt;TD width="80"&gt;Bid&lt;/TD&gt;&lt;TD width="80"&gt;Ask&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20"&gt;1/02/2014 09:00&lt;/TD&gt;&lt;TD align="right"&gt;12&lt;/TD&gt;&lt;TD align="right"&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20"&gt;1/02/2014 09:02&lt;/TD&gt;&lt;TD align="right"&gt;14&lt;/TD&gt;&lt;TD align="right"&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20"&gt;3/02/2014 09:10&lt;/TD&gt;&lt;TD align="right"&gt;13&lt;/TD&gt;&lt;TD align="right"&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20"&gt;4/02/2014 09:11&lt;/TD&gt;&lt;TD align="right"&gt;13,5&lt;/TD&gt;&lt;TD align="right"&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20"&gt;5/02/2014 09:24&lt;/TD&gt;&lt;TD align="right"&gt;12,2&lt;/TD&gt;&lt;TD align="right"&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20"&gt;6/02/2014 09:35&lt;/TD&gt;&lt;TD align="right"&gt;11,3&lt;/TD&gt;&lt;TD align="right"&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;What I would like is to merge these database in order to obtain the last BID and ASK values just before the trade. This would give this&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" height="174" style="width: 367px; height: 166px;"&gt;&lt;TBODY&gt;&lt;TR style="border: inherit solid inherit;"&gt;&lt;TD class="xl65" height="21" width="100"&gt;id_trade&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="107"&gt;Datetime&lt;/TD&gt;&lt;TD width="80"&gt;Bid&lt;/TD&gt;&lt;TD width="80"&gt;Ask&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit solid inherit;"&gt;&lt;TD class="xl66" height="21" style="border-top: none;" width="100"&gt;320&lt;/TD&gt;&lt;TD class="xl67" style="border-top: none; border-left: none;" width="107"&gt;1/02/2014 09:00&lt;/TD&gt;&lt;TD align="right"&gt;12&lt;/TD&gt;&lt;TD align="right"&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit solid inherit;"&gt;&lt;TD class="xl66" height="21" style="border-top: none;" width="100"&gt;240&lt;/TD&gt;&lt;TD class="xl67" style="border-top: none; border-left: none;" width="107"&gt;1/02/2014 09:03&lt;/TD&gt;&lt;TD align="right"&gt;14&lt;/TD&gt;&lt;TD align="right"&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit solid inherit;"&gt;&lt;TD class="xl66" height="21" style="border-top: none;" width="100"&gt;356&lt;/TD&gt;&lt;TD class="xl67" style="border-top: none; border-left: none;" width="107"&gt;3/02/2014 09:12&lt;/TD&gt;&lt;TD align="right"&gt;13,5&lt;/TD&gt;&lt;TD align="right"&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit solid inherit;"&gt;&lt;TD class="xl66" height="21" style="border-top: none;" width="100"&gt;908&lt;/TD&gt;&lt;TD class="xl67" style="border-top: none; border-left: none;" width="107"&gt;4/02/2014 09:15&lt;/TD&gt;&lt;TD align="right"&gt;13,5&lt;/TD&gt;&lt;TD align="right"&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit solid inherit;"&gt;&lt;TD class="xl66" height="21" style="border-top: none;" width="100"&gt;1452&lt;/TD&gt;&lt;TD class="xl67" style="border-top: none; border-left: none;" width="107"&gt;5/02/2014 09:23&lt;/TD&gt;&lt;TD align="right"&gt;13,5&lt;/TD&gt;&lt;TD align="right"&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit solid inherit;"&gt;&lt;TD class="xl66" height="21" style="border-top: none;" width="100"&gt;6543&lt;/TD&gt;&lt;TD class="xl67" style="border-top: none; border-left: none;" width="107"&gt;6/02/2014 09:45&lt;/TD&gt;&lt;TD align="right"&gt;11,3&lt;/TD&gt;&lt;TD align="right"&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I've been thinking a lot about this merge but I don't see how to do it. Could you please help me with it ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 07:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160040#M41721</guid>
      <dc:creator>crikriek</dc:creator>
      <dc:date>2014-06-29T07:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160041#M41722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;crikriek,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need a unique key on both data sets to perform the merge.&amp;nbsp; I don't know your data, but I imagine something like symbol id_trade should work.&amp;nbsp; If you can get those variables on both files, then you can use code like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=trades nodupkey; by symbol id_trade; run; *check log to ensure there are no dups;&lt;/P&gt;&lt;P&gt;proc sort data=spread nodupkey; by symbol id_trade; run; *check log to ensure there are no dups;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data trade_info;&lt;/P&gt;&lt;P&gt;merge trades (in=a) spread (in=b);&lt;/P&gt;&lt;P&gt;by symobl id_trade;&lt;/P&gt;&lt;P&gt;if a;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code above performs a left outer join.&amp;nbsp; IOW, it keeps all the records from data set a (trades) and attaches information from data set b if the keys match.&amp;nbsp; If you want an&amp;nbsp; inner join which only keeps those records that match then use "if a &amp;amp; b;" instead of "if a;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Bill&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 10:05:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160041#M41722</guid>
      <dc:creator>BillJones</dc:creator>
      <dc:date>2014-06-29T10:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160042#M41723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I guess right, You are coming from Euro ? and If your requirement is not too high,SQL can achieve that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data x;
input id_trade&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Datetime &amp;amp; anydtdtm.;
format &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Datetime Datetime.;
cards;
320 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1/02/2014 09:00
240&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1/02/2014 09:03
356&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3/02/2014 09:12
908&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4/02/2014 09:15
1452 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5/02/2014 09:23
6543 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6/02/2014 09:45
;
run;
data y;
input Datetime &amp;amp; anydtdtm.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(Bid&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Ask&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;) (: commax.);
format &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Datetime Datetime. Bid commax12.2 ;
cards;
1/02/2014 09:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;13
1/02/2014 09:02&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;15
3/02/2014 09:10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;14
4/02/2014 09:11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13,5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;14
5/02/2014 09:24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12,2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;13
6/02/2014 09:35&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11,3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;14
;
run;
proc sql;
create table want as 
 select x.*,bid,ask
&amp;nbsp; from x,y
&amp;nbsp;&amp;nbsp; where&amp;nbsp; x.Datetime-y.Datetime ge 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; group by id_trade
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having min(x.Datetime-y.Datetime)=x.Datetime-y.Datetime ;
quit;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 10:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160042#M41723</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-06-29T10:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160043#M41724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you guys. I really appreciate your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the solution of Xia Keshan best suits my needs. I was actually thinking about smthg like that. (And yes I come from Euro &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 10:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160043#M41724</guid>
      <dc:creator>crikriek</dc:creator>
      <dc:date>2014-06-29T10:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160044#M41725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xia Keshan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having trouble with the implementation of the code. I'm very new in SAS programming and I surely do'nt get all the subtilities of the program. Here's what I typed. LSV in my library. Trades_students_2012 is the dataset with the trades information and Orders_students_2012 is the one with the orders information. Time_OB is the name of the datetime in the orders_students_2012 dataset. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as &lt;/P&gt;&lt;P&gt; select lsv.trades_students_2012.*,bid, ask&lt;/P&gt;&lt;P&gt;&amp;nbsp; from lsv.trades_students_2012,lsv.orders_students_2012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; where&amp;nbsp; lsv.trades_students_2012.Datetime-lsv.orders_students_2012.Time_OB ge 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by id_trades&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having min(lsv.trades_students_2012.Datetime-lsv.Orders_students_2012.Time_OB)=lsv.trades_students_2012.Datetime-lsv.orders_students_2012.Datetime ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also have another problem since the column Datetime in the Trades dataset has been created by myself. I had the date and I had the time so I did this&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; alter table lsv.Trades_students_2012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; add datetime date label='datetime';&lt;/P&gt;&lt;P&gt;Proc sql; &lt;/P&gt;&lt;P&gt;update lsv.Trades_students_2012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set datetime= dhms(date,hour(time),minute(time), second(time));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it right ? Could you please help me with all this ? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 09:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160044#M41725</guid>
      <dc:creator>crikriek</dc:creator>
      <dc:date>2014-06-30T09:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160045#M41726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't post your real data. I just guess something . you can wrap all these SQL statement into one proc sql and use alias to make code succinct .&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; alter table lsv.Trades_students_2012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; add datetime date label='datetime';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;update lsv.Trades_students_2012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set datetime= dhms(date,hour(time),minute(time), second(time));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select &lt;STRONG&gt;a.&lt;/STRONG&gt;*,bid, ask&lt;/P&gt;&lt;P&gt;&amp;nbsp; from lsv.trades_students_2012&lt;STRONG&gt; as a&lt;/STRONG&gt; ,lsv.orders_students_2012 &lt;STRONG&gt;as b&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; where&amp;nbsp; &lt;STRONG&gt;a.&lt;/STRONG&gt;Datetime-&lt;STRONG&gt;b.&lt;/STRONG&gt;Time_OB ge 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by id_trades&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having min(&lt;STRONG&gt;a.&lt;/STRONG&gt;Datetime-&lt;STRONG&gt;b.&lt;/STRONG&gt;Time_OB)=&lt;STRONG&gt;a.&lt;/STRONG&gt;Datetime-&lt;STRONG&gt;b.&lt;/STRONG&gt;Datetime ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 12:22:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160045#M41726</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-06-30T12:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160046#M41727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot ! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nevetheless my two datasets are huge (3GB and 2GB) so the procedure takes too much time and space. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any other way to do it ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 07:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160046#M41727</guid>
      <dc:creator>crikriek</dc:creator>
      <dc:date>2014-07-01T07:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160047#M41728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Data step is &lt;STRONG&gt;fast&lt;/STRONG&gt; if your dataset is sorted by datetime. You can merge/interleave the 2 datasets.&lt;/P&gt;&lt;P&gt;The problem is, that you cannot use a &lt;STRONG&gt;merge/by&lt;/STRONG&gt; statement, because time stamps are not exactly equal.&lt;/P&gt;&lt;P&gt;You cannot use a &lt;STRONG&gt;set/by&lt;/STRONG&gt; statement, because in that case when we read from one of the datasets, the information from the other dataset is lost.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The solution is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set y(in=inY keep=datetime) x(in=inX keep=datetime);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by datetime;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if inY then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set y;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if inX then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set x;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 09:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160047#M41728</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2014-07-01T09:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160048#M41729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Gergely.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm thinking about the SyncJoin algorithm. I read this is a faster way to operate faster the cartesian product. Unfortunately I don't know how to apply it in my case.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 12:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160048#M41729</guid>
      <dc:creator>crikriek</dc:creator>
      <dc:date>2014-07-01T12:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160049#M41730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have looked at the paper describing SyncJoin. If you have a many-to-many relationship, my code won’t work. If it’s one-to-many (or many-to-one) I believe it is at least as fast as SyncJoin.&lt;/P&gt;&lt;P&gt;In the SAS log, you will see, that data step reads each data set 2 times. But in practice we make one-pass through the data. The data is still in the cache, when we re-read it. There is a version of this code that avoids this “apparent re-read”, but it’s complicated.&lt;/P&gt;&lt;P&gt;Have you tried it? You just need to change the names of the tables (x and y to lsv....).&lt;/P&gt;&lt;P&gt;I've used this technique in several projects on millions of rows.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 13:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160049#M41730</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2014-07-01T13:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160050#M41731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the following could help you understand what &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Gergely&lt;/SPAN&gt;'s code was trying to achieve. Of course, your data must be sorted already. or try Hash Table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data x;
input id_trade&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Datetime &amp;amp; anydtdtm.;
format&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Datetime Datetime.;
cards;
320&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1/02/2014 09:00
240&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1/02/2014 09:03
356&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3/02/2014 09:12
908&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4/02/2014 09:15
1452&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5/02/2014 09:23
6543&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6/02/2014 09:45
;
run;
data y;
input Datetime &amp;amp; anydtdtm.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (Bid&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ask&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) (: commax.);
format&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Datetime Datetime. Bid commax12.2 ;
cards;
1/02/2014 09:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13
1/02/2014 09:02&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15
3/02/2014 09:10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14
4/02/2014 09:11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13,5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14
5/02/2014 09:24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12,2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13
6/02/2014 09:35&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11,3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14
;
run;
data want(drop=bid ask);
 set y x(in=inx);
 by Datetime;
 retain _bid _ask;
 if not missing(bid) then _bid=bid;
 if not missing(ask) then _ask=ask;
if inx;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 13:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160050#M41731</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-07-01T13:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160051#M41732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks&amp;nbsp; a lot guys&amp;nbsp; it worked perfectly !! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jul 2014 09:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160051#M41732</guid>
      <dc:creator>crikriek</dc:creator>
      <dc:date>2014-07-03T09:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets with different but similar columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160052#M41733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good to know . That is the reason why I love this place, you can still learn something new or good idea. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jul 2014 13:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merging-two-datasets-with-different-but-similar-columns/m-p/160052#M41733</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-07-03T13:34:40Z</dc:date>
    </item>
  </channel>
</rss>

