<?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: Can SAS give different output when we have duplicates in join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/768796#M243881</link>
    <description>&lt;P&gt;Unless you go to some length to force things do not expect SQL to process anything in a given order. If sequence of operation is important then a data step merge may be a better approach. Or if the data is truly a transaction and the desired result is one output record per match then a data step UPDATE may be more in order.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Sep 2021 14:28:15 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-09-21T14:28:15Z</dc:date>
    <item>
      <title>Can SAS give different output when we have duplicates in join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/768776#M243871</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 datasets A and B with a key variable "Customer_id".&lt;/P&gt;&lt;P&gt;Dataset A does not have duplicates, however, Dataset B have duplicate key value but the complete record is not duplicate. consider this as a transaction dataset with mulitple amount for each "customer_id".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when i try to do left join of dataset A with Dataset B, in the result dataset C, I would be getting multiple records for "customer_id" which has duplicate values. This is clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is my problem statement is that, will the order of the duplicate customer_id i.e the records of the Customer_id with duplicates differ when we run it each time ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As far as i know, SAS reads the data record by record and hence this should not change, however, wanted to have an expert opinion or check if my understanding is not correct.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 13:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/768776#M243871</guid>
      <dc:creator>Jagadeesh2907</dc:creator>
      <dc:date>2021-09-21T13:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS give different output when we have duplicates in join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/768796#M243881</link>
      <description>&lt;P&gt;Unless you go to some length to force things do not expect SQL to process anything in a given order. If sequence of operation is important then a data step merge may be a better approach. Or if the data is truly a transaction and the desired result is one output record per match then a data step UPDATE may be more in order.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 14:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/768796#M243881</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-21T14:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS give different output when we have duplicates in join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/768885#M243898</link>
      <description>SQL doesn't respect order of rows at all. You cannot assume it will generate the same order unless you explicitly control it. &lt;BR /&gt;Data steps will by design to some degree but it also assumes that the data being provided is always in the exact same order.</description>
      <pubDate>Tue, 21 Sep 2021 16:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/768885#M243898</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-21T16:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS give different output when we have duplicates in join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769003#M243942</link>
      <description>this explains my difference. thank you for this point. how can i force SQL to follow a certain order ? is it by sorting the datasets which are needed to be joined ?</description>
      <pubDate>Wed, 22 Sep 2021 05:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769003#M243942</guid>
      <dc:creator>Jagadeesh2907</dc:creator>
      <dc:date>2021-09-22T05:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS give different output when we have duplicates in join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769004#M243943</link>
      <description>Thank you Rezza, how can i explicitly control this through SQL ? is it by sorting the datasets before join or there are any other ways ?</description>
      <pubDate>Wed, 22 Sep 2021 05:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769004#M243943</guid>
      <dc:creator>Jagadeesh2907</dc:creator>
      <dc:date>2021-09-22T05:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS give different output when we have duplicates in join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769007#M243946</link>
      <description>&lt;P&gt;You need a variable (or several variables) with which you can force the order in the ORDER BY clause of PROC SQL.&lt;/P&gt;
&lt;P&gt;Note that this will be less performant than establishing the order first with PROC SORT and then join in a DATA step.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 05:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769007#M243946</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-22T05:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS give different output when we have duplicates in join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769008#M243947</link>
      <description>&lt;P&gt;SQL never guarantees a processing order. That's a "feature" of the language.&lt;/P&gt;
&lt;P&gt;You &lt;EM&gt;should&lt;/EM&gt; generate a sequential read, if reading from a SAS V9 dataset, if you specify the&amp;nbsp; &amp;nbsp;&lt;FONT face="courier new,courier"&gt;proc sql nothreads;&lt;/FONT&gt;&amp;nbsp; &amp;nbsp;option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When reading multiple tables, sorting them by the join key &lt;EM&gt;should &lt;/EM&gt;prevent that &lt;FONT face="courier new,courier"&gt;proc sql&lt;/FONT&gt; generate a sort, and it &lt;EM&gt;should&lt;/EM&gt; read both tables sequentially if the &lt;FONT face="courier new,courier"&gt;nothreads&lt;/FONT&gt;&amp;nbsp;option is used. Ultimately, the SQL optimiser makes the decision.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 05:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769008#M243947</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-09-22T05:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS give different output when we have duplicates in join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769083#M243982</link>
      <description>&lt;P&gt;With SQL the only way to guarantee the sort order is via an Order clause AFTER the join.&lt;/P&gt;
&lt;P&gt;Even though due to some SAS specifics there might be some cases where you get the desired sort order also without an order by clause, you never should not attempt to implement this way because it's inherently not how SQL works.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 09:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-give-different-output-when-we-have-duplicates-in-join/m-p/769083#M243982</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-22T09:45:35Z</dc:date>
    </item>
  </channel>
</rss>

