<?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: Need a sorted data before MERGING???? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127055#M260264</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"Merging" data sets together can be done in many ways, one of which is the data step MERGE statement. This does require a sorted dataset as Steve has stated, but a SQL JOIN can also merge datasets and does not require a sort in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 Oct 2013 14:46:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2013-10-29T14:46:58Z</dc:date>
    <item>
      <title>Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127053#M260262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anybody tell me, why do we need a sorted data before merging while it can be sort after merging as well?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Anand&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Oct 2013 14:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127053#M260262</guid>
      <dc:creator>AnandSahu</dc:creator>
      <dc:date>2013-10-29T14:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127054#M260263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Because, unlike a SQL join, a merge is essentially a row-by-row operation, and if the keys are not in the same order on both data sets, the merge can't proceed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Steve Denham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Oct 2013 14:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127054#M260263</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2013-10-29T14:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127055#M260264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"Merging" data sets together can be done in many ways, one of which is the data step MERGE statement. This does require a sorted dataset as Steve has stated, but a SQL JOIN can also merge datasets and does not require a sort in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Oct 2013 14:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127055#M260264</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-10-29T14:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127056#M260265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;While there are many ways to do the 'Merging' without presorting the data, such as Proc SQL, Hash(), Proc Format among others, I suppose you are asking use of Merge statement in Data Step.&lt;/P&gt;&lt;P&gt;Data Step is sequential utility, meaning it goes through obs from top down, one by one till the end of the table. So when doing the merge by, it only makes sense that both tables are presorted by 'BY' variable, where data step is able to check and exhaust the same values of&amp;nbsp; 'BY' variable from both table at the same time. I can't imagine any other way to do the "merge" given the way how it works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Oct 2013 14:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127056#M260265</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-10-29T14:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127057#M260266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;my question is specific about Merging using Merge statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Oct 2013 15:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127057#M260266</guid>
      <dc:creator>AnandSahu</dc:creator>
      <dc:date>2013-10-29T15:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127058#M260267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What hasn't been mentioned is that while the observations need to be "presented" to the MERGE in order.&amp;nbsp; The contributing data sets don't have to be physically sorted.&amp;nbsp; Can you think of a way to logically "sort" a data set?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Oct 2013 15:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127058#M260267</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-10-29T15:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127059#M260268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you referring TAGSORT option in Proc Sort where only the 'by' variable get sorted Or are you referring Sortedby= dataset option where a table is only allegedly sorted?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Oct 2013 03:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127059#M260268</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-10-30T03:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127060#M260269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was thinking of INDEX.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Oct 2013 07:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127060#M260269</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-10-30T07:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127061#M260270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yep I was thinking the same thing.&amp;nbsp; Another option to logically "sort" a dataset is to use a SPDE dataset, where the engine returns the data in sorted order according to the BY variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And most merges via SQL do a sort under the covers.&amp;nbsp; So, while it may be "syntactically elegant" not to pre-sort your data, it's still sorting behind the scenes.&amp;nbsp; Use the _method option on the SQL statement to get more details on how SQL is doing the merge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's probably outside the scope of this thread to go into all the scenarios when SQL sorts/doesn't sort.&amp;nbsp; But further details are in this excellent Usage Note by Paul Kent.&amp;nbsp; IMO all users of SQL should read this &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;&lt;A href="http://support.sas.com/techsup/technote/ts553.html" title="http://support.sas.com/techsup/technote/ts553.html"&gt;TS-DOC: TS-553 - SQL Joins -- The Long and The Short of It&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Oct 2013 08:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/127061#M260270</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2013-10-30T08:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need a sorted data before MERGING????</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/387647#M260271</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was trying to find the answer to the same question and below explanation gives you better understanding i hope.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The merge join works by simultaneously reading and comparing the two sorted inputs one row at a time.&amp;nbsp; At each step, we compare the next row from each input.&amp;nbsp; If the rows are equal, we output a joined row and continue.&amp;nbsp; If the rows are not equal, we discard the lesser of the two inputs and continue.&amp;nbsp; Since the inputs are sorted, we know that we are discarding a row that is less than any of the remaining rows in either input and, thus, can never join.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;We can express the algorithm in pseudo-code as:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;get first row R1 from input 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;get first row R2 from input 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;while not at the end of either input&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if R1 joins with R2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (R1, R2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get next row R2 from input 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if R1 &amp;lt; R2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get next row R1 from input 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get next row R2 from input 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Source :&lt;A href="https://blogs.msdn.microsoft.com/craigfr/2006/08/03/merge-join/" target="_blank"&gt;https://blogs.msdn.microsoft.com/craigfr/2006/08/03/merge-join/&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Aug 2017 17:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-sorted-data-before-MERGING/m-p/387647#M260271</guid>
      <dc:creator>bsharath</dc:creator>
      <dc:date>2017-08-13T17:39:46Z</dc:date>
    </item>
  </channel>
</rss>

